If you want to buy something worth a certain amount, the best method is to overestimate by more than the expected slippage. We have a method on the SDK to estimate the required fromAmount you need to get a toAmount on the destination chain. It uses coingecko prices to approximate a number.
Get a fromAmount based on fromToken, toToken and toAmount.
Example usage:
constETH=squid.getTokenData("0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE","1");constUSDC=squid.getTokenData("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","1");constusdcToEth=awaitsquid.getFromAmount({ fromToken:USDC, toAmount:"1", toToken:ETH}); // expected: ~1600constethToUsdc=awaitsquid.getFromAmount({ fromToken:ETH, toAmount:"200", toToken:USDC}); // expected: ~0.12...// you can also specify slippage percentage (default is 1.5%)constusdcToEth3=awaitsquid.getFromAmount({ fromToken:USDC, toAmount:"1", toToken:ETH, slippagePercentage:3}); // expected: ~1648