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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

V1 - Swap quote mismatch #36

Open
kasia-antos opened this issue Jun 13, 2022 · 2 comments
Open

V1 - Swap quote mismatch #36

kasia-antos opened this issue Jun 13, 2022 · 2 comments
Assignees
Labels
bug Something isn't working enhancement New feature or request wontfix This will not be worked on

Comments

@kasia-antos
Copy link

Hi 馃憢

I'm trying to get fixed input swap quote and I noticed it's not correct for some pools. In below example PAGO/ALGO pool on the testnet.

from tinyman.v1.client import TinymanTestnetClient

client = TinymanTestnetClient(algod_client)

asset1 = client.fetch_asset(92772865)
asset2 = client.fetch_asset(0)
amount = 80
asset_in = asset1

pool = client.fetch_pool(asset1, asset2)
quote = pool.fetch_fixed_input_swap_quote(asset_in(amount * 10 ** asset_in.decimals), slippage=0.05)

I get the following quote for ALGO out amount and min out amount

image

while in the Tinyman app I get

image

which is almost the same but still slightly different.

When I make the transaction from the app the value I receive is matching the minimum value from the app but it seems like the total value (min + excess) is matching the value calculated by the SDK https://testnet.algoexplorer.io/tx/group/MEYPju6fy6LvBzph49xU%2BmvYyj3bpdf4A0FlmYTykU0%3D

image

image

image

Looks like the bug is on the app side not SDK but maybe you can double check it and confirm?

@gokselcoban
Copy link
Contributor

gokselcoban commented Nov 15, 2022

Hi @kasia-antos , I have double-checked it and I confirm this case; thank you for reporting it.

The reason is rounding error. The smart contract only supports integers, and division results are rounded down to an integer (Ex. 10/4=2). SDKs should follow the same arithmetic to be able to get the exact result.

We will be checking the possible improvements.
The JS SDK uses big interger and results are converted to int directly, but Python SDK converts the float results to the integer at the end.

The result calculated on the web app should be closer to the actual result. We need to double-check this part.

The effect will be less for the assets with decimal places. In this case, PAGO has no decimal places so the input amount is 80 micro unit, rounding error is more visible. For ALGO, which has 6 decimals, 80 Algo is 80.000.000 micro-unit. So, I assume fixing this is important but not urgent.

@gokselcoban gokselcoban self-assigned this Nov 15, 2022
@gokselcoban gokselcoban added bug Something isn't working enhancement New feature or request labels Nov 16, 2022
@gokselcoban gokselcoban changed the title Swap quote mismatch V1 - Swap quote mismatch Dec 16, 2022
@gokselcoban
Copy link
Contributor

gokselcoban commented Dec 30, 2022

Update: This issue is fixed for Tinyman V2 calculations.

@gokselcoban gokselcoban added the wontfix This will not be worked on label Dec 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants