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

Adding sails DEX #547

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Adding sails DEX #547

wants to merge 1 commit into from

Conversation

MedovTimur
Copy link
Contributor

No description provided.

Copy link
Contributor

@LouiseMedova LouiseMedova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Gas runs out during transactions that are not atomic. Critical sections, the handle reply hook, and checking the attached gas amount could be used.
  2. 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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. What will happen if an error occurs during the token transfer, but the state has already been changed earlier?
  2. 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same here.

  1. The transfer occurs after the state changing
  2. 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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. The state is also changed before the transfers.
  2. If an error occurs during the second transfer, the tokens will not be returned to the user.
  3. 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.
  4. There is also the issue of running out of gas.

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