* Update all dependencies to 1.7.3, fix issues
* Remove esm from mocha
* Fix missed token test
* Also update rust version
* token-swap: update tolerance on sim test
* Run `cargo clippy --fix` for needless_borrow errors
* Rerun cargo fmt
* WIP: Implementation of the remainder of stablecurve methods
* Edits based on PR feedback
* revert SwapVersion
* PR fixes
* checked add / sub
* reverted to using RoundDirection instead of LiquidityProviderOperaiton
* removed LiquidityProviderOperation enum
* Revert flipped parameters
* initial attempt at noramlized_value
* use d for noramlize value for stable curve
* TradeDirection instead of RoundDirection for trading_tokens_to_pool_tokens
* reimplemented the trading_tokens_to_pool tokens function for stable
* Typo
* fix rounding errors in pool_tokens_to_trading_tokens
* try different values of amplification factor in test for stable curve
* fixed broken tests, use constant_product normalized_value function
* use cubic solver
* fix noramlize_value function bad maths
* redid noramlized value for one last time
* added more proptests
* Get tests to work
* Fixup for prod usage
Co-authored-by: Yutaro Mori <me@yutaromori.com>
Co-authored-by: Jon Cinque <jon.cinque@gmail.com>
* Add spl-token program id check helper function. Add program id to instruction bindings.
* Run cargo fmt
* Fixup tests
* Skip ATA tests when custom token program-id
Co-authored-by: Tyera Eulberg <tyera@solana.com>
* token-swap: Fix withdrawal all tokens slippage
When withdrawing, the slippage check is done before `min`ing the token a
and b amounts, which makes it possible to ignore the desired slippage,
and lose out on a lot more than expected.
This has an additional knock-on effect. When burning all of the pool
tokens, it becomes impossible to ever use it again.
* Check for slippage after getting the actual amount that would be
traded
* Re-initialize the pool token amount on the next deposit if all pool
tokens were burned
Fixes#1629
* Fmt + clippy
* Deposit one side on 0 pool tokens just gives new supply back
* stake-pool: Use checked_ceil_div for withdraw calc
When a stake account is totally removed from a stake pool by the
manager, there's a chance that the operation would not take enough of
the manager's pool tokens by 1 due to truncation.
Do a ceiling division instead, and refactor ceiling division into the
math library.
* Use new function name on CLI
* Cargo fmt
* Add rounding specification for deposit / withdraw
The fuzzing test was improved to make sure that the value of pool tokens
(minus fees) never changed, which revealed a calc bug with deposits and
withdrawals. If someone withdraws, they can take additional small
value out of the pool in the form of truncated value.
Before, deposit and withdrawal used the same calculation, rounding up the token
A and B amounts. Remember that deposit / withdrawal specify the pool
token amount, and calculate the amount of A / B required to get to that
many pool tokens. On withdrawal, we were giving back a little bit too
much. The concept is that everything would even out since a deposit is
required for a withdrawal, which makes everything a wash.
Fuzzing found this issue very quickly! The change is to introduce a
rounding parameter to avoid ever giving away too much value, either
during deposit or withdrawal.
* Cleanup
* Add withdraw test
* Cleanup
* Cargo fmt
* Remove curve tests from fuzzing cfg
* Update JS test
* Cleanup test
* Update honggfuzz again
* Fix fee on JS test
* Force correct version of honggfuzz for CI (remove later)
* Improve value tests using PreciseNumber everywhere
* Fix ceiling
* Add comment for 0 tokens
* Fix ceiling div, add in constant price calc
* Revert ceiling division as template and use trait, too much boilerplate
* Run cargo fmt
* Add user transfer authority to swap instruction
* Add user transfer authority to deposit all
* Add authority to withdraw all
* Add authority to deposit one
* Add authority to withdraw one
* Update fuzzer
* Add user transfer authority to JS