Commit Graph

79 Commits

Author SHA1 Message Date
Jon Cinque 1411d8b4fd
stake-pool: Option to use transfer + allocate + assign for PDA (#2920) 2022-02-16 16:22:46 +01:00
Tyera Eulberg f4e0cae144
Fix up helper to create rent-exempt accounts (#2720) 2022-01-08 15:51:17 -07:00
Dmitri Makarov 65b49073f4
Decrease the stake pool size due to the new mem op syscall base cost (#2705) 2022-01-05 14:26:13 -08:00
Jon Cinque 6ee008d256
Update SDK to 1.9.2, fix warnings (#2674)
* Update SDK to 1.9.2, fix warnings

* Upgrade honggfuzz

* Use `get_latest_blockhash` correctly
2021-12-28 23:02:47 -05:00
Jon Cinque 1f4b65153f
Update tests to prepare for `BanksClientError` (#2657)
* Update tests to prepare for `BanksClientError`

* Remove import from record tests
2021-12-23 13:08:06 -05:00
Jon Cinque 8c9f8a0088
stake-pool: Reduce maximum pool size (#2654)
* stake-pool: Reduce huge pool size in tests

* stake-pool: Reduce supported maximum size
2021-12-21 13:10:12 +01:00
Jon Cinque ba08b6e662
stake-pool: Mint extra reserve lamports as pool tokens on init (#2636)
* stake-pool: Mint extra reserve lamports as pool tokens on init

* Wait more aggressively in py test

* Simplify test
2021-12-14 18:45:15 +01:00
Jon Cinque d5ac6b883b
stake-pool-py: Add simple rebalance bot (#2630)
* stake-pool-py: Add simple rebalance bot

* Fixup test

* Refactor flaky tests

* Create vote earlier in test

* Duplicate create_vote call causes stall

* Wait more aggressively
2021-12-13 13:17:07 +01:00
Jon Cinque 01765b9953
stake-pool: Reduce wait for active stake merges (#2553)
* stake-pool: Reduce wait to one epoch for active merges

* Remove stake_program references

* Remove credits observed point from docs
2021-11-01 15:14:49 +01:00
Jon Cinque cd3f5ae9fe
stake-pool: Add test for withdrawing all, with fee (#2550) 2021-10-26 22:50:16 +02:00
Jon Cinque 4ab60e6794
stake-pool: Also set the sol deposit authority on init (#2532) 2021-10-20 01:45:00 +02:00
Jon Cinque 1a48523a80
stake-pool: Remove copied stake program code (mostly) (#2526)
* stake-pool: Remove (mostly) the copied stake program

* Remove references to stake_program in CLI
2021-10-19 16:48:56 +02:00
Jon Cinque f95e390dd4
stake-pool: Clarify stake deposit fee (#2520) 2021-10-19 12:26:50 +02:00
Jon Cinque 4658815e9f
stake-pool: Force pools to only use the SPL token program (#2521) 2021-10-19 01:39:57 +02:00
Jon Cinque 50b5597fcf
stake-pool: Improve error when overdrawing on decrease (#2522) 2021-10-19 00:45:46 +02:00
Jon Cinque 13375afff2
stake-pool: Add last epoch values for APR calculation (#2491)
* stake-pool: Add last epoch values for APR calculation

* Bump versions for release
2021-10-07 00:01:15 -04:00
Jon Cinque b80c10f406
stake-pool: Add withdraw-sol command + CLI + docs (#2475)
* stake-pool: plumb sol withdraw fee and authority

* Add sol withdraw instruction and processor

* Cleanup sysvar usage

* Fix stack size violation

* Add tests

* Add CLI support

* Add docs for new command

* Integrate review feedback
2021-10-05 22:44:03 -04:00
Jon Cinque 5337a4f17f
stake-pool: Use `matches!` to allow for fix in underlying error (#2453) 2021-09-26 23:58:30 +02:00
Jon Cinque 87a5c79347
stake-pool: Reduce minimum stake per validator to 0.001 SOL (#2373)
* stake-pool: Reduce minimum stake per validator to 0.01 SOL

* Lower the limit to 0.001 SOL
2021-09-08 02:10:31 +02:00
Jon Cinque 87b74cfa4c
stake-pool: Combine create stake and add validator (#2371) 2021-09-03 00:54:51 +02:00
Jon Cinque fc0d6a2db7
stake-pool: Split from stake account during removal (#2367)
If the stake pool gives over the validator stake account to the staker,
they may keep it and make it impossible to re-add that validator in the
future.

Split the whole amount into a new stake account on removal.
2021-09-02 01:38:16 +02:00
Jon Cinque 7c8e65292a
stake-pool: Add seed for transient stake account (#2304)
* stake-pool: Add seed for transient stake account

* Use new functions in CLI

* Put back transient stake seed prefix
2021-08-20 14:15:02 -04:00
jon-chuang 25cc0cffc5
stake-pool: seed suffix to allow creating & discarding multiple transient stake accs (#2298)
* seed suffix to allow creating & discarding multiple transient stake accs

* "suffix"

* fix tests, memcmp and len, reorder struct fields

* remove proptest
2021-08-20 01:14:42 -04:00
jon-chuang 4b0f59e9c6
Use stake pool's declared token ID rather than hard-coded (#2286)
* fix

* tests use hard-coded `&spl_token::id()` - fine since we need a baseline

* use spl_token::id
2021-08-17 16:36:32 -04:00
jon-chuang e168a5db92
stake-pool: skip manager fee if invalid account, check new manager fee owned by `spl_token` (#2277)
* fix

* add check if new manager fee is spl token program

* Convert manager fee info check to fail only inside `Result` box

* update also checks validity of manager fee info

* clippy
2021-08-17 16:32:47 -04:00
jon-chuang 494ef1d54e
stake-pool: `DepositStake` only issues tokens for `delegation.stake` + `min(undelegated_stake_rent, additional_lamports)` (#2270)
* charge fees for `sol_deposit_lamports` in `DepositStake` separately

* do not add extra lamports beyond rent

* change name: `additional_lamports`

* fix: put `meta_exempt_reserve` limit on additional lamports instead

* debugging tools

* saturating_add

* make rent quota conditional

* eagerly update total_stake_lamports

* fix tests to reflect increase in `total_staked_lamports`
2021-08-17 16:27:50 -04:00
Han Yang 85f81ae45c
fix stake-pool: preferred validator can be set to validator not part of the pool (#2272)
* deny set preferred validator if validator is about to be removed, add tests

* fix copy paste error

* only allow Active validators to be set to preferred validator

Co-authored-by: Jon Cinque <jon.cinque@gmail.com>

Co-authored-by: Jon Cinque <jon.cinque@gmail.com>
2021-08-17 16:02:02 -04:00
Han Yang 11a5551446
fix: stake-pool require signature in SetManager (#2273)
* add check for new_manager's signature in SetManager

* cli arg edit
2021-08-14 00:16:43 -04:00
jon-chuang 974541c158
stake-pool: Update fee changes only once per epoch (#2269)
* fix

* test for withdrawal fee

* merge conflict changes
2021-08-14 00:09:33 -04:00
Jon Cinque c0be064278
stake-pool: Address a few points post-liquid staking (#2252) 2021-08-11 01:33:06 -04:00
jon-chuang 87d88bd078
Stake pool/liquid deposits (rebased on new master) (#2141)
* rename staking instructions

* modify DepositStake te to include manager fees and referrer, continue _stake refactor, referral fees WIP

* initialize with fees, fee application, checks

* inline functions

* temporarily substitute u8 for bool until borsh gets it's * straight

* set deposit fee

* apply deposit and referral fee to liquid deposit_sol too

* add set-deposit-fee, unify cli interface

* set-referral-fee

* full feature set for liquid deposits (?)

* add tests/set_referral_fee.rs

* fix missing serialization in process_set_referral_fee

* remove duplicated test case in tests/set_withdrawal_fee.rs

* tests WIP, numbers dont add up after non-zero deposit fee

* fix error, fix tests

* deposit_sol tests. Requires additional changes to work properly

* simplify deposit_sol tests, add referral fee tests for deposit and deposit_sol

* add `sol_deposit_authority`.

* split deposit_sol() & deposit_sol_with_authority(), cli sol_deposit --from, minor cleanup

* cli deposit-sol from argument should take keypair instead

* commands: set-sol-deposit-authority, show

* cli: pretty print stake pool struct

* chore: comments/naming

* fmt, clippy

* add args for `create-pool`

* mistake in the cli

* `system_prog` is `read_only`, require sig from `stake_deposit_auth`

* change deposit-sol-authority arg to optional acount, rename instruction::withdraw->withdraw_stake, remove unnecesary sys_prog arg for withdraw_stake

* resolve simple nits and suggestions

* cli: change default referrer to user's token receiver account instead of pool manager

* cli: remove show command, add fees to list command, rename pool -> epoch

* update tests for removed unnecessary referral fee account owner check and deposit sol

* cli changes: create ephemeral account for deposit_sol

* specify pool token type for account info name

* add check for manager fee acc in deposit_sol

* Apply suggestions from code review

Co-authored-by: Jon Cinque <jon.cinque@gmail.com>

* fix non-rebased bug

* SetDepositStakeAuthority

* refactor + tests + cli

* fmt

* clippy

* remove unnecessary comment

* ASK keyword

* unset deposit auth

* combine set fee instructions

* clippy

* applying suggestions

* apply out-of-date check only for FeeTypes that need it

* add fee + user = new tokens check

* Fix test

* Unify `SetDepositAuthority` instruction

* fmt

Co-authored-by: dhy1996 <dhy1996@live.com.sg>
Co-authored-by: Jesse Y. Cho <f8122dac91@gmail.com>
Co-authored-by: Jon Cinque <jon.cinque@gmail.com>
2021-08-11 00:15:45 -04:00
Jon Cinque f7384c1fb3
stake-pool: Make it impossible to leech value (#2218) 2021-08-05 10:25:37 -04:00
Jon Cinque 2414022606
stake-pool: Don't assess withdrawal fee from fee account (#2180) 2021-07-29 17:56:50 -04:00
jon-chuang e9e4d36211
Stake pool/withdrawal fee (#2107)
* stake-pool: Add new fee fields for liquid staking and arbitrage

* incorporate withdrawal fee to withdrawal instruction, refactor calculating fees into Fee method

* update withdraw instruction to take manager fee account, revert divide by 0 edge-case removal

* initialize with withdrawal fee, modify integration tests to incorporate withdrawal fee

* extra safety check, prevent divide by 0

* patch Initialize for other tests

* decrease HUGE_POOL_SIZE to fit compute budget

* set_withdrawal_fee, initialize conditions

* Handle current withdrawal fee = 0 case

* add tests for withdrawal fees

* baseline fee increase is explicit constant

* withdrawal_fee for cli for initialize

* fmt, fix cli

* obey clippy

* clean up cli, add increase from 0 tests.

* add cli: set-withdraw-fee

* apply suggestions for code review

* remove 1_000_000 denom limit

* remove denom limit tests, inline, checked muls

* apply suggestions for code review

* referral fee

* tests: use local copy to calculate_withdrawal_fee instead of fetching from chain

Co-authored-by: Jon Cinque <jon.cinque@gmail.com>
Co-authored-by: dhy1996 <dhy1996@live.com.sg>
2021-07-25 20:08:16 -04:00
Jon Cinque 5159608d03
stake-pool: Update pool token supply on update, in case of burns (#2108) 2021-07-20 00:36:08 +02:00
Jack May df480b9795
Breakup stake-pool update test transactions (#2084)
* Breakup stake-pool update test transactions

* nudge
2021-07-14 10:26:31 -07:00
Jon Cinque 99a6e95106
stake-pool: Optimizations for 4k validators (#2041)
* In-place serde

* Add cleanup instruction

* Add BigVec tests, clarify lifetimes
2021-07-08 22:50:28 +02:00
Jon Cinque ac2f9e09a4
stake-pool: Fixup accounting on increase transient account (#1985) 2021-06-29 00:51:54 +02:00
Jon Cinque 21f8af34e7
Update all solana dependencies to 1.7.3, fix issues (#1958)
* 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
2021-06-25 00:39:08 +02:00
Jon Cinque 6c9ca0d83d
stake-pool: Use `delegation.stake` for accounting (#1934)
* stake-pool: Use `delegation.stake` for accounting

* Clippy

* Improve test and remove spl-math dependency

* Address smaller review comments

* Fix calculation, improve tests

* Clippy

* Remove esm from mocha

* Revert "Remove esm from mocha"

This reverts commit c0f25ab543c808a1daf3474df4ef851bc994fc6c.
2021-06-24 20:30:59 +02:00
Jon Cinque de693dc219
stake-pool: Fail initializing if mint has a freeze authority (#1949) 2021-06-22 21:38:08 +00:00
Jon Cinque a081c2859b
stake-pool: Wait to apply new fee (#1922)
* Add `next_epoch_fee` field and fix serde

* Only update fee after the epoch is passed

* Update docs
2021-06-15 23:40:14 +00:00
Jon Cinque ddf9efa330
stake-pool: Add ability to withdraw from transient stakes (#1890)
* stake-pool: Add ability to withdraw from transient stakes

It's possible for a very malicious pool staker to constantly increase /
decrease the stake on validators, making it impossible for people to get
their SOL out.

Update the accounting to know how much of the stake is active and how
much is transient and allow users to withdraw from transient accounts,
but only if there's no more active stake.

* Remove mut ickiness
2021-06-11 20:50:59 +00:00
Jon Cinque ba99e44bff
stake-pool: Add reserve stake check on update pool balance (#1866) 2021-06-04 23:08:32 +02:00
Jon Cinque 450b2d511a
stake-pool: Add preferred deposit / withdraw validator accounts (#1831)
* stake-pool: Add set preferred validator instruction

* Add functionality for using the preferred deposit / withdraw

* Add CLI support
2021-06-01 12:45:27 +02:00
Jon Cinque ea98e6bf73
stake-pool: Fix fee calculation (#1764)
* stake-pool: Fix fee calculation

* Remove unwraps, widen one more calc
2021-05-20 11:53:06 +00:00
Jon Cinque cebb3176b2
stake-pool: Add helper instruction creators for stake pool integration (#1706)
* stake-pool: Add more instructions for easier usage

* Add extra check (shouldn't be necessary, but who knows?)
2021-05-11 20:48:58 +00:00
Jon Cinque d68608c440
stake-pool: Re-enable tests, avoid warping so much (#1687) 2021-05-10 12:33:56 +00:00
Jon Cinque 11e207cc85
stake-pool: Add user transfer authority on withdraw (#1640)
The stake pool expects pool tokens to be delegated to the withdraw
authority before performing a withdrawal. If a user delegates too many
tokens to the withdraw authority, anyone else can take the rest of their
tokens by doing their own withdrawal.

Delegate pool tokens to an ephemeral keypair and sign with that.
2021-04-27 12:53:46 +00:00
Jon Cinque 14bdbdc3ac
stake-pool: Add ability to remove a validator that has deactivating transient stake (#1624)
* Add status enum

* Add ability to remove validator with transient stake

* Only account validator stake if active

* Fix merge conflicts
2021-04-27 13:24:39 +02:00