-
Notifications
You must be signed in to change notification settings - Fork 202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(target_chains/ton): add parse_price_feed_updates #2099
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
2 Skipped Deployments
|
|
||
() update_price_feeds(int msg_value, slice data) impure { | ||
load_data(); | ||
tuple parse_price_feeds_from_data(slice data) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tuple is how we deal with arrays in func
tuple price_feeds = parse_price_feeds_from_data(data); | ||
int num_updates = price_feeds.tlen(); | ||
int update_fee = single_update_fee * num_updates; | ||
int compute_fee = get_compute_fee( | ||
WORKCHAIN, | ||
UPDATE_PRICE_FEEDS_BASE_GAS + (UPDATE_PRICE_FEEDS_PER_UPDATE_GAS * num_updates) | ||
); | ||
throw_unless(ERROR_INSUFFICIENT_GAS, msg_value >= compute_fee); | ||
int remaining_msg_value = msg_value - compute_fee; | ||
|
||
;; Check if the sender has sent enough TON to cover the update_fee | ||
throw_unless(ERROR_INSUFFICIENT_FEE, remaining_msg_value >= update_fee); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because most of the parsing is performed first now and the fee checks only afterwards, a user that has sent slightly too little funds still needs to pay for a lot of the processing and only gets back a small amount (or nothing is the gas limit is reached during parsing and no bounce message sent). Not necessarily a problem, as this cannot be abused to steal funds, more a user experience thing.
I guess the alternative would be to parse the num_updates
first, do the fee calculation, and then do the rest of the parsing. But would probably make the code a bit more convoluted / uglier, as the data parsing is then split into two different functions.
No description provided.