Commit Graph

44 Commits

Author SHA1 Message Date
Tyera Eulberg f4e0cae144
Fix up helper to create rent-exempt accounts (#2720) 2022-01-08 15:51:17 -07: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 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 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 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 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 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
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 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
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 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 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 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 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 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
Jon Cinque c149b0a46e
stake-pool: Add depositor key on init, required on deposit (#1616)
* stake-pool: Add depositor key on init, required on deposit

Some stake pools need to be private, and not allow outside depositors.

Enhance the existing deposit authority in the stake pool be configurable
on initialization, and then require its signature on deposit.

The existing deposit authority is a program address, making deposits
permissionless. This allows a pool creator to set their own deposit_authority on
initialization. In a great turn of events, almost everything else works
the same way!

Here's the current workflow for deposit, where the user calls
stake_program::authorize and stake_pool::deposit in the same
transaction:

* stake_program::authorize assigns staker and withdraw authority to the
  stake pool deposit authority
* stake_pool::deposit
    - uses the deposit authority to assign authority on the deposited
  stake account to the stake pool withdraw authority
    - uses the withdraw authority to merge the deposited stake into the validator stake

The deposit authority must "sign" the transaction in order to reassign
authority to the withdraw authority. Currently, as a program address, it
can just do that. With this change, if the deposit authority is set
during initialization, then that deposit authority must sign the
instruction.

There's also a little update for ease-of-use to always do the
stake_program::authorize in the same transaction as stake_pool::deposit.
This way, in case someone tries to deposit into a forbidden stake pool, the
whole transaction will bail and their stake will stay as theirs.

* Address review feedback

* Fix rebase issues
2021-04-22 21:34:41 +02:00
Jon Cinque 804a61e558
stake-pool: Increase lower limit for increase-validator-stake (#1620)
* stake-pool: Increase lower limit for increase-validator-stake

* Update test amounts in line with limit
2021-04-22 20:49:30 +02:00
Jon Cinque 08c4cb530a
stake-pool-cli: Add increase / decrease validator stake (#1619) 2021-04-22 00:20:35 +00:00
Jon Cinque fdba05714d
stake-pool: Add merging transient stakes in update (#1618)
* Add check for transient stake account activation on removal

* Add proper merging logic during update

* Format + clippy

* Add max possible validators

* Disallow removal for any transient stake state

* Reduce number of accounts for BPF instruction usage
2021-04-22 01:41:15 +02:00
Jon Cinque 53c86493e6
stake-pool: Add reserve stake and decrease / increase validator stake instruction (#1617)
* Add reserve stake account

* Add decrease validator stake instruction

* Cargo fmt

* Add increase instruction

* Add more increase tests

* Fix set fee tests

* Fix clippy in tests

* Add test-bpf feature to increase / decrease tests
2021-04-21 22:20:27 +02:00
Jon Cinque 40ebfc6917
stake-pool: Set fee (#1604)
* stake-pool: Add set_fee instruction

* Add more tests

* Add set-fee CLI instruction

* Update documentation

* Cargo fmt

* Re-format

* Fix clippy
2021-04-21 14:20:55 +02:00
Jon Cinque 30671aa5b3
stake-pool: Rework add / remove validator to not use pool tokens (#1581)
* Rework remove

* Add tests

* Transition to checked math

* Update CLI for new types / instructions

* Cargo fmt

* Rename voter_pubkey -> vote_account_address

* Remove max check

* Update validator balance test
2021-04-21 13:06:43 +02:00
Jon Cinque 71e5e556c4
stake-pool: Assess fee as a percentage of rewards (#1597)
* stake-pool: Collect fee every epoch as proportion of rewards

* Add more complete tests

* Update docs
2021-04-15 12:10:17 +02:00
Jon Cinque 7f89183c0d
stake-pool: Ensure zero pool token supply on init (#1572) 2021-04-05 20:06:40 +02:00
Jon Cinque 092432f1e1
stake-pool: Separate manager from owner (#1560)
* stake-pool: Separate manager from owner

* Add manager pubkey to stake pool
* Differentiate manager functions from owner functions
* Include a `set_manager` function to be used by the owner
* Change the term `owner` to `authority` in the CLI for clarity

* Rename manager -> staker and owner -> manager

* Split staker, manager, and token owner in CLI

* "Do not disturb the boss"
2021-04-02 10:56:12 +02:00
Michael Vines 48ab307cad Reboot program address derivation helpers 2021-03-31 23:57:44 -07:00
Michael Vines 67cb90f39c De-tangle processor/state dependencies 2021-03-31 22:00:20 -07:00
Michael Vines eb1bf2eb44 Code cleanup v0 2021-03-31 12:28:08 -07:00
Jon Cinque 9f38a6f4b2
Rework create validator stake account (#1539) 2021-03-31 00:54:15 +02:00
Jon Cinque 9e4f190633
stake-pool: Rename instructions / structs (#1536)
* stake-pool: Rename instructions / structs

* Cargo fmt

* Fix proptest
2021-03-30 23:54:06 +02:00
Jon Cinque d815ba9b8e
stake-pool: Add borsh support and specify size on creation (#1505)
* lending: Update JS tests to solana-test-validator

* Add solana tools install

* Fix oopsie on the path

* Move where deployed programs go

* stake-pool: Add borsh support and size on creation

We can't specify the size in the instruction unfortunately, since we'd
only have 10kb max for the validator list. At roughly 50 bytes per
validator, that only gives us 200 validators.

On the flip side, using Borsh means we can allow the validator stake list
to be any size!

* Add AccountType enum

* Remove V1 everywhere

* Add max validators as parameter and get_instance_packed_len

* Add test for adding too many validators

* Clippy
2021-03-27 13:42:29 +01:00
Atticlab LLC 11df4aa5ec
Various postponed fixes and changes to the stake pool program (#1200)
* Various postponed fixes and changes to the stake pool program

* Fixed PR comments

* Fixed no-signature validator stake account add test

Co-authored-by: Yuriy Savchenko <yuriy.savchenko@gmail.com>
2021-02-10 17:42:28 +01:00
Yuriy Savchenko 13826294ef
Stake pool: test coverage for most of the program errors (#1134)
* Stake pool: test coverage for most of the program errors

* Fixes to stake pool tests PR comments
2021-01-27 23:35:25 +01:00
Jon Cinque 14daf0d370
Stake pool: adding pool balance confirmation (Redo of #960) (#1116)
* Added validator stake account list storage, deprecated old tests

* Added join and leave stake pool instructions, error messages refactoring

* Stake pool tests refactoring, tests for join and leave pool added

* Added validator stake account creation instruction, join/leave pool instructions renamed, version field added

* Formatting fixes

* Added update list/pool instructions (no tests yet), updated deposit instruction logic, claim instruction removed, refactoring

* Updated deposit logic and tests, updated withdraw logic and added tests, refactoring

* Stake pool CLI updated to work with new deposit/withdraw instructions, claim usage removed

* Added validator stake account management and balance update commands to the stake pool CLI, updated dependency versions, updated devnet program address

* Merge conflicts fixed

* Removed deprecated tests

* Fixes for review comments

* Additional program id checks across the code

* Formatting errors fixed

* Changed minimum stake balance in CLI, removed deprecated tests, removed check for stake history id

* Added TODO for stake account warmup status check

* Cargo.lock conflict fix

* Formatting fixed

* Update Cargo lock file for CI

* Pin themis version of subtle

Co-authored-by: Yuriy Savchenko <yuriy.savchenko@gmail.com>
2021-01-21 14:48:46 +01:00