Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Staked collateral #248

Merged
merged 59 commits into from
Dec 24, 2024
Merged

Staked collateral #248

merged 59 commits into from
Dec 24, 2024

Conversation

jgur-psyops
Copy link
Contributor

@jgur-psyops jgur-psyops commented Sep 20, 2024

  • Adds a large number of Anchor tests in TS (e2e coverage now up to deposit/borrow).
  • Adds a Bankrun instance to the TS test suite.
  • Adds the ability to use SOL assets staked to vanilla Solana staking (https://github.com/anza-xyz/agave/tree/master/sdk/program/src/stake) as collateral to borrow SOL.
  • Validators (or anyone: the process is permissionless) will use the Single Pool program (https://github.com/solana-labs/solana-program-library/tree/master/single-pool) to create an "LST" that uses that just that validator (unlike a traditional LST which will have several validators). After a bank for this LST is created, the LST can be deposited as collateral in the main pool. Only SOL can be borrowed against this kind of asset.
  • Adds Bankrun simulation of creating a validator, native SOL staking + delegation from users, deposit into a Single Pool, and integration with mrgnlend

Running the test suite:
anchor build -p marginfi -- --no-default-features (repeat for other programs as needed)
anchor test --skip-build

Extras:

  • Permissionless ix to create LST banks in an existing group
  • Per-group global settings account that controls the config for all staked collateral banks under that group (see init_staked_settings, edit_staked_settings, and propagate_staked_settings)
  • Pricing of LST to include appreciation (uses lst mint supply and stake's sol pool balance)

Notes for launch:

  • Deploy the single-pool program to mainnet
  • Update api/FE for the new asset_tag field in bank.config
  • Prepare infra to init, edit, and propagate staked collateral settings for groups
  • Update the existing SOL bank's asset_tag to ASSET_TAG_SOL
  • Accounts made on the SOL bank prior to this update will use ASSET_TAG_DEFAULT instead of ASSET_TAG_SOL, so they will not be able to be used with STAKED accounts. However, this is probably a good thing: we want users to make a new account for this feature.

@jgur-psyops jgur-psyops added the enhancement New feature or request label Sep 20, 2024
@jgur-psyops jgur-psyops requested a review from jkbpvsc October 31, 2024 19:57
Comment on lines 1460 to 1467
/// Because the mint (and thus corresponding stake pool) of a staked collateral bank cannot
/// update after inception, this function validates just the oracle, ignoring the lst mint and
/// sol pool. This function works only for banks configured as StakedWithPythPush, and otherwise
/// errors
pub fn validate_staked_oracle_setup(&self, ais: &[AccountInfo]) -> MarginfiResult {
OraclePriceFeedAdapter::validate_staked_bank_config_light(self, ais)?;
Ok(())
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the idea here that we don't have to pass 2 extra accounts when configuring a stake collateral bank?
Also the oracle setup should be validated only when the oracle is update which shouldn't happen unless we expect the underlying pyth oracle to change?
I would maybe think that saving on code complexity (additional code) is worth more than saving 2 extra accounts when calling an admin instruction

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's for config. The underlying pyth oracle can still update, so we still want to validate it, but the stake mint and pool accounts cannot update after bank inception, so checking them is not necessary after initial add pool.

We could recycle the existing validate_oracle_setup if you prefer but I thought splitting it was cleaner, having it branch within the function will be a slightly larger code change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consolidated validation into one large function

@jgur-psyops jgur-psyops merged commit b2e769d into main Dec 24, 2024
5 checks passed
@jgur-psyops jgur-psyops deleted the staking-collat-init branch December 24, 2024 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants