solana-program-library/ci
Jon Cinque 40b7690a58
swap: Add rounding correction for deposit / withdraw (#1061)
* 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
2021-01-15 18:17:27 +01:00
..
cargo-build-test.sh Disable client_ristretto build 2020-12-03 05:39:55 +00:00
env.sh Implement docusaurus build, deployment and CI hooks (#129) 2020-07-16 10:13:45 -06:00
fuzz.sh fuzz: Dump error file as hex instead of using cat (#1054) 2021-01-11 23:04:11 +01:00
install-build-deps.sh token-swap: Add fuzzer for swap / withdraw / deposit (#875) 2020-11-30 13:01:31 +01:00
install-program-deps.sh swap: Add rounding correction for deposit / withdraw (#1061) 2021-01-15 18:17:27 +01:00
js-test-token-lending.sh Simplify github action with scripts (#769) 2020-11-04 10:50:07 +08:00
js-test-token-swap.sh Simplify github action with scripts (#769) 2020-11-04 10:50:07 +08:00
js-test-token.sh Port token js tests from solana-localnet to solana-test-validator 2020-12-17 21:24:30 -08:00
rust-version.sh Pin rust nightly version until ICE is fixed (#1063) 2021-01-14 15:28:44 +08:00
solana-version.sh Update to Solana 1.5.0 2020-12-17 21:24:30 -08:00