Skip to content
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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

cctdaniel
Copy link
Contributor

No description provided.

Copy link

vercel bot commented Nov 6, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
api-reference ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 8, 2024 1:22pm
proposals ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 8, 2024 1:22pm
staking ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 8, 2024 1:22pm
2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
component-library ⬜️ Ignored (Inspect) Visit Preview Nov 8, 2024 1:22pm
insights ⬜️ Ignored (Inspect) Visit Preview Nov 8, 2024 1:22pm


() update_price_feeds(int msg_value, slice data) impure {
load_data();
tuple parse_price_feeds_from_data(slice data) {
Copy link
Contributor Author

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

Comment on lines 218 to 229
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);

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants