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

Mainnet: OPUL/ALGO Pool Returning Wrong Quote #13

Closed
albertshin opened this issue Nov 19, 2021 · 5 comments
Closed

Mainnet: OPUL/ALGO Pool Returning Wrong Quote #13

albertshin opened this issue Nov 19, 2021 · 5 comments

Comments

@albertshin
Copy link

albertshin commented Nov 19, 2021

Running the following on mainnet:

ALGO = client.fetch_asset(0)
OPUL = client.fetch_asset(287867876)
pool = client.fetch_pool(OPUL, ALGO)
quote = pool.fetch_fixed_input_swap_quote(ALGO(2500), slippage=0.01)

returns, for example, 2955 as quote.

In reality, this is actually 0.2955, so the quote is actually is off by exactly 10000 for some reason.

@fergalwalsh
Copy link
Contributor

I think the issue here is due to the differing number of decimals per asset.

All amounts and prices in the SDK are expressed in terms of the microunits of the assets. The prices/amounts you see displayed in the Tinyman UI are adjusted according to the defined number of decimals for the asset. All internal calculation on the blockchain and in the SDKs use the microunit integer representation.

When you write ALGO(2500) it means 0.002500 Algo because Algo has 6 decimals.
2500.0 Algo would be ALGO(2500_000_000).

Opul has 10 decimals so 1000 in microunits for example is actually 0.0000001 Opul.

While the display price or ratio between the assets might be 1:0.2955 the actual ratio of their microunits could be 1:2955 due to the difference in the number of decimals.

@albertshin
Copy link
Author

Hi, this seems to be an issue in v1.1. I understand @fergalwalsh's comment on differing decimals and "adjust" for this after I get the quote from the pool, but it seems that fetch_fixed_input_swap_quote is assuming that the number of decimals is the same across all units which does not seem to be the expected output for some pools where the input and output have different decimals.

@gokselcoban
Copy link
Contributor

gokselcoban commented Feb 3, 2022

@albertshin, Can you please share an example? It would be great to share an example code with expected and real values.

Sorry, you have already did.

@gokselcoban
Copy link
Contributor

gokselcoban commented Feb 3, 2022

Microunits don't have an decimal place. Microunit should be an integer, so your expectation0.2955 is not valid.

fetch_fixed_input_swap_quote is assuming that the number of decimals

I think, you don't need to consider decimal place in this calculation, since microunits don't have an decimal place.

@albertshin
Copy link
Author

albertshin commented Feb 3, 2022

I see what you mean. Re-reading Fergal's original reply that everything is expressed in microunits makes more sense now. Thanks!

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

No branches or pull requests

3 participants