We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
in typescript implementation fo ConstantProductCurve swapWithoutFees gives different output then one in rust/anchor
swapWithoutFees
ts implementation:
static swapWithoutFees(sourceAmount: BN, swapSourceAmount: BN, swapDestinationAmount: BN): SwapWithoutFeesResult { const invariant = swapSourceAmount.mul(swapDestinationAmount); const newSwapSourceAmount = swapSourceAmount.add(sourceAmount); const [newSwapDestinationAmount, _newSwapSourceAmount] = checkedCeilDiv(invariant, newSwapSourceAmount); const sourceAmountSwapped = _newSwapSourceAmount.sub(swapSourceAmount); const destinationAmountSwapped = swapDestinationAmount.sub(newSwapDestinationAmount); if (destinationAmountSwapped.isZero()) throw Error("destinationAmountSwapped is zero"); return { sourceAmountSwapped, destinationAmountSwapped, }; }
rust/anchor:
pub fn swap_base_input_without_fees( source_amount: u128, swap_source_amount: u128, swap_destination_amount: u128, ) -> u128 { // (x + delta_x) * (y - delta_y) = x * y // delta_y = (delta_x * y) / (x + delta_x) let numerator = source_amount.checked_mul(swap_destination_amount).unwrap(); let denominator = swap_source_amount.checked_add(source_amount).unwrap(); let destinsation_amount_swapped = numerator.checked_div(denominator).unwrap(); destinsation_amount_swapped }
They give different amounts of destinationAmountSwapped.
destinationAmountSwapped
The text was updated successfully, but these errors were encountered:
No branches or pull requests
in typescript implementation fo ConstantProductCurve
swapWithoutFees
gives different output then one in rust/anchorts implementation:
rust/anchor:
They give different amounts of
destinationAmountSwapped
.The text was updated successfully, but these errors were encountered: