The SDK's fee calculation does not have this logic, so if the amount of input is small, fee calculation results in zero. As a result, on-chain, the amount of input is less than the amount of fee and the output is lower than expected.
Fixes:
Change to the same fee calculation logic as spl-token-swap
Added test cases to constant-product-quote.test.ts and stable-quote.test.ts
Note:
To avoid exceptions when obtaining estimates, if the fees is greater than the input, the input is treated as zero.
Bug Details: calculate_fee function of spl-token-swap includes a process to set the fee to 1 if it is truncated to 0. https://github.com/solana-labs/solana-program-library/blob/813aa3304022528cbf3cf7a3d32bca339194a492/token-swap/program/src/curve/fees.rs#L56
The SDK's fee calculation does not have this logic, so if the amount of input is small, fee calculation results in zero. As a result, on-chain, the amount of input is less than the amount of fee and the output is lower than expected.
Fixes:
Note: To avoid exceptions when obtaining estimates, if the fees is greater than the input, the input is treated as zero.