orca-so / typescript-sdk

The Orca SDK contains a set of simple to use APIs to allow developers to integrate with the Orca platform.
155 stars 49 forks source link

fix: minimum fee of one token #108

Closed yugure-orca closed 1 year ago

yugure-orca commented 1 year ago

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.