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

About query pool swap rate #1

Open
marco-sundsk opened this issue Oct 4, 2021 · 2 comments
Open

About query pool swap rate #1

marco-sundsk opened this issue Oct 4, 2021 · 2 comments

Comments

@marco-sundsk
Copy link

It looks like a query interface (view function) of contract that can return multiple pool states is neccessary for your solution.

And although there is a get_return view function in contract to estimate swap out amount according to swap in amount, I guess it is not what you need, cause you can not know the exactly amount of input in advance.

So I am considering to add a view function that can receive multiple pool id as a vector and return each liquidity amounts of each pool. Besides that, pool fee is more static and can be retrieved in advance from ref-finance backend data service.

Then, amountA, amountB and fee of each pool are all in your hand, the solution would go smoothly, wouldn't it? Is there anything else needed for this solution?

@giddyphysicist
Copy link
Owner

Hi @marco-sundsk , yes, we used the contract view function "get_pools" to get those states. This gave us the collection of pool structs that each contain fields for id, token_account_ids, amounts, total_fee, and shares_total_supply. For our solution, we mainly just need the fee and the reserves in the AMM (amounts field) associated with token A and token B. We didn't want to use the get_return function since that could broadcast user intent, and risk front-running. Since we already know how the pools calculate the expected token B output given a certain amount of token A input in a constant-product bonding curve AMM, we can calculate that on the front-end.
And as long as you have viewed the info of the fee, the reserves of A, and the reserves of B in each pool, that is all the data you need to run the parallel swap algorithm.
Let me know if you have any other questions! I'm happy to help.

@dongxuteng
Copy link

dongxuteng commented Feb 20, 2024 via email

Repository owner deleted a comment from redtree0 Feb 20, 2024
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