* 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
* Add extra check on instruction fuzz
* Refactor division
* Fix tests from fixed deposit math
* Fixup comments and cleanup fuzz
* Run fmt
* Address review feedback
* Fix JS test
* Add proptest-regressions to .gitignore, created from failed proptests
* Add proptests to ensure swapping maintains value
* Address review feedback
* Add doc to public test function
* Add instructions to deposit / withdraw one token
* Run cargo fmt
* Fix clippy issues
* Add JS interface
* Add tests for new instructions
* Run prettier
* Rename deposit and withdraw
* Rename withdraw -> withdraw all in program
* Rename single token instructions
* Update constant price curve conversion to/from pool tokens
* Add test for pool token conversion
* Fix tests
* run cargo fmt
* Assess fee on half source amount for conversion
* Add offset curve
* Fix for math
* Add PreciseNumber
* Use Balancer formulation for trading token -> pool token conversion
* Add round-trip conversion testing
* Add offset curve to JS
* Run cargo fmt
* Update JS test numbers for new calcs
* Integrate review feedback
* Allow for withdrawals when one side is 0
* Run cargo fmt
* Disallow deposits for offset curve
* Run cargo fmt
* Allow for withdrawals through 0
* Add price parameter for flat / constant price curve
This encompasses a lot of changes to properly support the constant price
curve, and fixes some old pain points to make the whole thing easier to
use, including:
* refactor fees out of the curve
* move all fee calculations into new Fees type
* modify constraints to only care about curve types and fee
* add price parameter into constant price curve (flat curve)
* Run cargo fmt and clippy
* Revert interface changes and math update
* Run cargo fmt
* Address review feedback
* Fix fraction validation for zeros
* Add extra check
* Add extra check on init
* Run cargo fmt
* Clippy
* Add token program id check on unpack
* Run cargo fmt
* Add checks for program id ownership on swap account
* Add truncation check during swapping
* Run cargo fmt
* Update truncation to ceiling the value
* Run cargo fmt
* Fix JS test
* Refund back not needed source tokens
* Run cargo fmt
* Add swap_without_fees method to trait
* Fix merge problem
Co-authored-by: Justin Starry <justin@solana.com>
* token-swap: Add fuzzer for swap / withdraw / deposit
* Run cargo fmt
* Make end-to-end testing work
* Fix test failures
* Cleanup for review
* Remove Clone trait for Initialize
* Fix building fuzz targets
* Fix fuzz withdraw logic to avoid ZeroTradingTokens error
* Cargo fmt
* Clippy / fmt again
* Integrate fuzzer in main workspace to share clippy / fmt
* Fix clippy
* Switch to stable honggfuzz that could work with BPF
* Update to most recent honggfuzz
* Add build / run requirements
* Add fuzz CI and cleanup for honggfuzz
* Revert to using fuzz feature to integrate with workspace
* Make fuzz script executable
* Refactor and cleanup
* Add nightly run
* Fix workflow typo
* Add runtime for pull request fuzz workflow
* Fix unrelated new clippy errors
* Stable curve math rewritten to 256-bit, reference simulation added with test integration
* Formatting error fixed
* Clippy warnings fixed
* Fixed dependencies to remove crates not supportinf bpf
* Fixed indentations
* Fixed lint errors
* Fixed format warnings
* Fixing clippy lint errors
* U256 math and simulation library refactoring, checked math used everywhere, other small fixes
* Fixed conversion to optional u128