raydium-io / raydium-sdk-V2-demo

Open-source Typescript SDK demos
83 stars 44 forks source link

fix problem with calc AmountOut and problem with find poolId #4

Closed kasrakhamesi closed 6 months ago

kasrakhamesi commented 6 months ago

I have 2 question. 1. https://github.com/raydium-io/raydium-sdk-V2-demo/issues/3 in this issue,I need find pool pair with search with back-end ( need exist that in this raydium-sdk-v2-demo ),but you tell me solution with raydium UI,but I need using it to find pool by baseMint and quoteMint in back-end

2.when using calcAmountOut in https://github.com/raydium-io/raydium-sdk-V2-demo/blob/master/src/amm/swap.ts

price has too different with https://raydium.io/swap

for example

if I want swap W-WSOL with amount : 1100 raydium UI show me : image

but /src/amm/swap.ts show me image

help me to fix it

cruzshia commented 6 months ago
  1. update sdk version to 0.0.38-alpha and reference: example
  2. due to huge amount of pools in Raydium, swap in Raydium UI is calculated best route by backend, sdk doesn't support routing swap, only support swap example for different types of pools (e.g. amm/swap, clmm/swap, cpmm/swap), the code you used in only for amm pool swap calculation, you can compare different swap amount in these types of pools and find the best one.