If a swap has a trading fee and a zero owner fee, when calculating the owner
fee to pool token conversion, the simulated trading fee will be non-zero
because we floor the trading fee to 1 token. If the input to trading
fee calculation is 0, then we will try to do `0 - 1` on an unsigned int,
which causes an underflow error. The fix is to simply return a 0 fee
for a 0 input.
* Use u128 for all the math but store in u64
* tests
* missing changes
* bulds
* specific conversion failure
* fix tests
* use large numbers
* Rebase and fix merge issue from new tests
Co-authored-by: Jon Cinque <jon.cinque@gmail.com>
* Add mints to swap info
* Add mints to JS
* Add fee account in SwapInfo / init
* Add test for 0 fee, init test fully
* Add withdraw command interface
* Add fee accounts to swap instruction
* Add calculations for swap and withdraw fees
* Run cargo fmt
* Add new fees to JS and test
* Review feedback: fixup instruction doc and clone
* Update order of accounts in instructions
* Run cargo fmt
* Fix owner fee pool token calculation to include trading fee
* Add owner fees to flat curve, per request
* Fix instruction comment numbering
* Add more errors types for clearer calculation errors
Add a check for withdrawing from fee account
* Cargo fmt
* Pass TokenSwap state into the constructor to simplify function calls
* WIP: Update program to return token_program_id
* Add tokenProgramId to js TokenSwapInfo object
* Address pr comments
* Remove TokenSwapInfo and use loadTokenSwap as the primary way to fetch TokenSwap metadata
* Fix module.d.ts
* Address pr comments
* Clarification on comments
Co-authored-by: Yutaro Mori <yutaro@umaproject.org>
* token-swap: Add token supply in invariant calculation
* Refactor state classes into curve components for future use
* Align pool initialization with Uniswap using geometric mean of token
amounts
* Fix deposit and withdraw instruction to work as a proportion of pool
tokens
* Add math utilities to calculate the geometric mean with u64
* Improve variable names
* Use a fixed starting pool size
* Run cargo fmt
* Update js tests with new pool numbers
* Run linting
* Remove math
* Fix BN type issues found by flow
* Pack instructions and state more efficiently
* SwapInfo and SwapInstruction are more memory-efficient, following the
example from SPL Token
* Remove unnecessary helper structs to make instructions clearer
* Error -> SwapError
* Update JS tests to reflect the change
* Integrate review feedback
* Fix local token-swap tests
* Change generation of program address to use a nonce
* Accept nonce properly in initialization
* Include nonce in TokenSwap structure
* Fixup serialization with new parameter (padding used for now)
* Update dependencies
Update toml / lock files
Fix token swap initialization end-to-end
Cleanup unit test to use `find_program_address`
Add / refactor tests
Most importantly, added a special test to make sure that
token_program_id is provided at the end of CPI instructions, since
unit testing did not pick up that problem, and it was tough to debug
during end-to-end testing
* Revert some testing changes for PR
* Update token-swap/program/src/processor.rs
Co-authored-by: Tyera Eulberg <teulberg@gmail.com>
* Integrate review comments
* Fmt and clippy
* Refactor for clippy
* Fmt again
* Fix npm lint error
* Clarify signers line as requested
Co-authored-by: Tyera Eulberg <teulberg@gmail.com>