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

Problem with buildTx apiv5 #101

Open
bogdanaks opened this issue Jan 24, 2022 · 2 comments
Open

Problem with buildTx apiv5 #101

bogdanaks opened this issue Jan 24, 2022 · 2 comments

Comments

@bogdanaks
Copy link

bogdanaks commented Jan 24, 2022

Hey!

I noticed a strange error, the buildTx method always returns the error "The rate has changed, please re-query the latest Price"
This error always occurs when exchanging stablecoins. In example: Network(Polygon), USDC/DAI

Also, if when initializing the class new ParaSwap(137, 'https://api.paraswap.io') with an address not on apiv5, then the same method with the same parameters was created successfully once, but then again the same error

Code example:

const paraSwap = new ParaSwap(137, 'https://api.paraswap.io')
const priceRoute: OptimalRate = await paraSwap.getRate(
       0x2791bca1f2de4661ed88a30c99a7a9449aa84174,
       0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063,
       1000000,
       side: SELL,
       network: 137
)

const txParams = await paraSwap.buildTx(
        0x2791bca1f2de4661ed88a30c99a7a9449aa84174,
        0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063,
        100000,
        99835030397689696,
        priceRoute,
        userAddress,
)

Response: error: "The rate has changed, please re-query the latest Price"

@plambir93kek
Copy link

Hi, i faced the same problem. when creating a transaction on the USDC/fUSDT pair in Fantom network. I tried sending a transaction via 'https://api.paraswap.io ' and https://apiv5.paraswap.io ' . How can i fix it?

@ColonelJ
Copy link
Contributor

ColonelJ commented Feb 3, 2022

You may need to add more slippage tolerance on your transaction parameters. Specifically, you should set the destAmount in buildTx to something lower than what is in the priceRoute, the lower you make it the less likely you are to see this error. For stablecoin->stablecoin swaps the rate shouldn't deviate much, so you don't need much slippage tolerance, but you still need something in case there are rounding/interpolation issues on our prices. It is normally recommended to deduct some % on the price you get from ParaSwap to handle slippage, but you could also fix some minimum price that you are willing to accept (may make more sense for swapping between USD stablecoins where you expect exchange rate close to 1). Hope that helps!

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