-
Notifications
You must be signed in to change notification settings - Fork 119
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
Adding sails DEX #547
base: master
Are you sure you want to change the base?
Adding sails DEX #547
Conversation
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.
- Gas runs out during transactions that are not atomic. Critical sections, the handle reply hook, and checking the attached gas amount could be used.
- The math is performed simply in integers, which causes quite rough rounding. We could consider using binary math operations (i.e., shifting for multiplication/division).
*user_liquidity += liquidity; | ||
} | ||
|
||
let request_a = vft_io::TransferFrom::encode_call(sender, program_id, amount_a); |
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.
- What will happen if an error occurs during the token transfer, but the state has already been changed earlier?
- What will happen if the gas runs out during the first transfer, between the first and second transfers, or after the second transfer?
|
||
// Transfer token A back to the user | ||
let request_a = vft_io::TransferFrom::encode_call(program_id, sender, amount_a); | ||
msg::send_bytes_for_reply(storage.token_a, request_a, 0, 0) |
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.
The same here.
- The transfer occurs after the state changing
- Running out of gas is a critical issue here
/// Determines the output token based on `out_is_a`. | ||
/// Calculates the output amount using the reserves and updates them accordingly. | ||
/// Transfers the input token to the DEX and the output token to the user. | ||
pub async fn swap(&mut self, in_amount: U256, out_is_a: bool) { |
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.
- The state is also changed before the transfers.
- If an error occurs during the second transfer, the tokens will not be returned to the user.
- During the swap, variables affecting the swap price are changed. Therefore, until the swap is fully completed (i.e., until all transfers have occurred), no one should be allowed to perform a swap.
- There is also the issue of running out of gas.
No description provided.