Commit Graph

119 Commits

Author SHA1 Message Date
Jon Cinque ac2f9e09a4
stake-pool: Fixup accounting on increase transient account (#1985) 2021-06-29 00:51:54 +02:00
Jon Cinque edf07b1f69
stake-pool: Update version for crate publish (#1967)
Finalize the stake pool struct for when a lockup will eventually be
present.
2021-06-25 21:34:48 +00: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
Lieu Zheng Hong 346075743e
stake-pool: Stake pool deserializer (#1656)
* first commit

* add schema for stakepool accounts

* got imports working

* add typescript support

* fix schema

* Change to use PublicKey type

* change to camelCase instead

* add type annotations to typescript classes

* add readme

* Add prettier linting

* add instructions to run

* add test section

* prettier clean up schema.ts

* convert index.js to index.ts

* actually use decode method available in Assignable

* rename stakepoolaccount so i can have a wrapper class

* add new class StakePool and change return type of getStakePoolAccounts

* remove extraneous .js files

* update schema to incorporate jon's comments

* remove unnecessary comments

* add helper functions to get individual accounts; cleaned up code

* add Fee, change denominator/numerator to BN

* Add enums so we can check what type an accountType is

* Remove name and ticker in StakePool class

* fix borshjs import

* change outdir to dist/ folder

* Edit package.json

* add toBuffer for schema.PublicKey

* add exports and default exports to index.ts

* fix trailing comma on tsconfig.json

* get mocha test harness working with ts-node, ts-mocha, esm

* fix borsh import

* clean up imports

* add working test script

* remove unneeded borshjs import

* add unit tests for both decodes (WIP)

* no need to console.log in testOnDevnet since we now have a test suite

* Add tests for ValidatorListAccount.decode

* add schema.decode.StakePoolAccount test

* Finish up

* reduce dependencies in package.json

* Add lint command to package.json

* Lint with prettier

* Update README.md with new commands

* Write explanatory comments in index.js

* Small linting change

* feat: introduce new borshjs deserializeUnchecked import

* lint: npm lint

* refactor: upgrade web3js version

* refactor: refactor type names

* refactor: npm run lint

* refactor: improve tsconfig.json

* feat: add declaration and declarationMap to tsconfig.json

* feat: allow getStakePoolAccounts to more robustly handle errors

* Update stake-pool/js/.gitignore

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

* Update stake-pool/js/package.json

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

* Update stake-pool/js/package.json

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

* Update stake-pool/js/package.json

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

* Update stake-pool/js/package.json

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

* refactor: modify `constructStakePoolSchema` to mutate in place

* lint: remove webpack.config.js

* lint: npm run lint

* lint: add comments above index.ts

* lint: lowercase schema

* feat: add full deserialization test

* Update stake-pool/js/package.json

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

* refactor: remove try-catch block in getStakePoolAccounts

* lint: lint

* refactor: use web3js pubkey

* refactor: move integration tests to separate file

* refactor: change test.js to do encode-decode loop

Co-authored-by: Jon Cinque <jon.cinque@gmail.com>
2021-06-23 14:18:45 +02:00
Jon Cinque 702f1478e8
stake-pool: Split transient stake account creation (#1950) 2021-06-22 21:45:47 +00: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
Tyera Eulberg e28af24443 Bump solana version 2021-06-14 16:02:27 -06: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 329f9c0912
stake-pool: Add explicit ownership checks (#1868) 2021-06-04 21:45:49 +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 454c75c711
stake-pool: Document writability of validator list (#1867) 2021-06-04 22:15:39 +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 b310c2a163
stake-pool: Add program_id to all instruction ctors (#1814) 2021-05-28 11:46:57 +02:00
Michael Vines ed0389f708 Add forward compatibility with solana-client 1.6.10 2021-05-22 00:00:33 -07: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 d4bbdf8224
stake-pool-cli: Bump version for release (#1713)
* stake-pool-cli: Bump version for release

* Update lock file
2021-05-12 13:20:48 +00:00
Jon Cinque 731bb6f57a
stake-pool: Bump version for release (#1707) 2021-05-11 21:46:49 +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
jordansexton f0b1cec4d8 stake-pool: minor typo fix 2021-05-07 13:50:35 -05:00
Trent Nelson 1f36ca301b Bump solana crates to v1.6.7 2021-05-05 04:39:49 +00:00
Jon Cinque 3dd6767297
stake-pool: Update versions for crate deployment (#1657) 2021-05-03 20:50:49 +00:00
Jon Cinque 9c63bc0b06
stake-pool-cli: All sorts of fixes (#1650)
While going back through the docs, I ended up doing a lot of the stake
pool CLI items:

* Deposit / withdraw command: Use associated token account by default
* Create command: Allow passing the stake pool and mint keypair (useful
  for testing)
* Create command: Split the transaction for pool creation (required to get under the
  transaction size limit)
* Add / remove validator command: take a validator vote account rather than stake
  account, which makes integration from outside tools a lot simpler
* Update command: add a `--force` flag to force the update
* Update command: add a `--no-merge` flag to not merge while updating
  (useful to allow the pool to work, even if the transient stake
  accounts are unmergeable)
* Withdraw: Add `--use-reserve` flag to withdraw from reserve
* Withdraw: Add `--vote-account` arg to specify which validator to
  withdraw from
2021-05-03 11:47:24 +02: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 61a53abf6f
stake-pool: Add ability to withdraw from reserve if no stake available (#1627) 2021-04-23 23:55:16 +02:00
Michael Vines 1e47030549 Update SPL to Solana v1.6.6 2021-04-23 13:39:51 -07: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 3613ffe3b0
hotfix: ignore tests that break with tip of 1.6 (#1622) 2021-04-22 12:30:47 +00: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 2b3f71ead5
stake-pool: Add rebalancing instruction interface (#1563)
* stake-pool: Add rebalancing instruction interface

* Address feedback

* Rename again

* Ignore rustdoc code
2021-04-09 12:32:21 +02:00
Jon Cinque 7f89183c0d
stake-pool: Ensure zero pool token supply on init (#1572) 2021-04-05 20:06:40 +02:00
Michael Vines 17dd53d5e8 Break up the UpdateValidatorListBalance instructions over multiple transactions 2021-04-05 08:50:57 -07:00
Michael Vines ee52f1d499 Reimplement `spl-stake-pool list` command to use the StakePool/ValidatorList as the primary source of information 2021-04-02 16:27:42 -07: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 eb6cd994b8 More variable renaming 2021-04-01 07:40:18 +00: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 b97849d206 Code cleanup v2 2021-03-31 19:52:17 -07:00
Michael Vines 2cd7adbf87 Code cleanup v1 2021-03-31 15:37:50 -07:00
Michael Vines eb1bf2eb44 Code cleanup v0 2021-03-31 12:28:08 -07:00
Jack May f390e12311
Allow for fixed error mappings (#1541) 2021-03-30 17:30:44 -07:00