-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/solana missing features #21
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
Draft
kostyamospan
wants to merge
62
commits into
main
Choose a base branch
from
feat/solana-missing-features
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 12 commits
Commits
Show all changes
62 commits
Select commit
Hold shift + click to select a range
8ceb4b2
feat: maxSupplyCap minter vault
dmytro-horbatenko f83e35c
feat: implement maxSupplyCap in minter vault configuration and migrat…
dmytro-horbatenko 289872b
refactor: remove migrate-minter-vault script
dmytro-horbatenko 74cc2b0
fix: move local scripts to verify
dmytro-horbatenko 7790383
Merge pull request #15 from midas-apps/feat/max-supply-cap
dmytro-horbatenko 6f9c085
feat: add safe approval methods for mint and redeem requests with sup…
dmytro-horbatenko 7e0cd4c
refactor: update vault_common account attributes in mint and redeem r…
dmytro-horbatenko 831d781
fix: improve error handling in amount conversion for redeemer
dmytro-horbatenko e1eccb7
fix: pull feed util
dmytro-horbatenko 6ad2028
fix: approve redeem request script args
dmytro-horbatenko 3ce30d4
Merge pull request #16 from midas-apps/feat/approve-at-price
dmytro-horbatenko 22e1b53
Merge branch 'main' into feat/chainlink-feed
kostyamospan f16970e
feat: arithemtic operaitions panic replaced with error code
kostyamospan 1befe7b
chore: basic timelock tests
kostyamospan dc7314b
chore: more squads scripts
kostyamospan 4644d35
chore: timelock deployment scripts
kostyamospan 4cf5cbe
chore: upgrade scripts
kostyamospan f79eb80
fix: comments
kostyamospan 56f8695
chore: timelock scripts
kostyamospan de43bdd
fix: timelock scripts
kostyamospan 0f58758
fix: typo
kostyamospan fc365d0
fix: log
kostyamospan bb9f79d
fix: timelock transfer authority
kostyamospan d4d704d
Merge remote-tracking branch 'origin/main' into feat/timelock
kostyamospan 601a014
fix: tests
kostyamospan 8e08b02
fix: toolchain
kostyamospan fae25f1
fix: resize instruction
kostyamospan 1b5268c
Merge branch 'feat/timelock' into feat/solana-missing-features
kostyamospan e221eed
fix: log
kostyamospan b02cea7
Merge branch 'feat/timelock' into feat/solana-missing-features
kostyamospan d0c3f5a
fix: target
kostyamospan abb8ccf
fix: timelock flows
kostyamospan d3cfbfc
Merge branch 'feat/timelock' into feat/solana-missing-features
kostyamospan 291966a
chore: draft account migration
kostyamospan 0cfa151
chore: migration to anchor 0.32.1
kostyamospan 6575510
fix: box instruction accounts
kostyamospan 52aad9b
feat: chainlink support
kostyamospan dd023c7
chore: draft growth feed
kostyamospan becd788
feat: growth feed with tests
kostyamospan 894d903
feat: migration from bankrun to litesvm
kostyamospan cf57a53
feat: minter vault migration instruction
kostyamospan 051d874
feat: manual feed migration instruction
kostyamospan cdfa03f
fix: migration folder rename
kostyamospan 563d3cd
fix: bankrun fn names removed
kostyamospan 036018a
chore: log level added tests
kostyamospan 56f9643
fix: todos removed
kostyamospan f281b36
chore: manual feed growth deployment scripts
kostyamospan d16fe18
fix: lint config toml
kostyamospan efd829d
chore: migration ts scripts
kostyamospan 247271d
fix: ts format/lint
kostyamospan 05df587
fix: lint commands package json
kostyamospan 67a81b0
fix: rust codestyle
kostyamospan c424dd6
fix: tests
kostyamospan 687067b
fix: int errors, clippy configuration
kostyamospan 4578177
fix: price utils additional validation
kostyamospan 9a6e52e
fix: midas vault utils downcast handle
kostyamospan cbf1619
fix: get deviatioin zero div check
kostyamospan be91335
fix: squads tests
kostyamospan 75e1c39
fix: transfer upgrade authority
kostyamospan d963a54
feat: separate roles for price update and request approve/reject
kostyamospan bf4c78c
fix: package
kostyamospan 554b12d
fix: tests
kostyamospan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
173 changes: 173 additions & 0 deletions
173
...ms/midas-vault/src/instructions/minter_vault/safe_approve_mint_request_at_current_rate.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| use access_control::{program::AccessControl, state::AccountAccessControlRoleState}; | ||
| use anchor_lang::prelude::*; | ||
| use anchor_spl::token_interface::{Mint, TokenAccount, TokenInterface}; | ||
| use data_feed::state::FeedState; | ||
| use token_authority::{ | ||
| constants::ac_roles as ac_roles_token_authority, program::TokenAuthority, | ||
| state::TokenAuthorityState, | ||
| }; | ||
|
|
||
| use crate::{ | ||
| constants::ac_roles, | ||
| state::{MintVaultRequestState, MinterVaultState, VaultCommonState}, | ||
| utils::{close_account, get_token_rate, minter, Closable}, | ||
| }; | ||
|
|
||
| #[derive(Accounts)] | ||
| #[instruction(request_id: u64)] | ||
| pub struct SafeApproveMintRequestAtCurrentRate<'info> { | ||
| /// Account with vault admin role | ||
| #[account(mut)] | ||
| pub authority: Signer<'info>, | ||
|
|
||
| /// CHECK: | ||
| /// request user account | ||
| #[account( | ||
| mut, | ||
| address = mint_request.user | ||
| )] | ||
| pub user_account: AccountInfo<'info>, | ||
|
|
||
| /// Vault common state account | ||
| #[account( | ||
| address = minter_vault.common_vault | ||
| )] | ||
| pub vault_common: Account<'info, VaultCommonState>, | ||
|
|
||
| /// Admin role of authority | ||
| #[account( | ||
| seeds = [AccountAccessControlRoleState::SEED, vault_common.ac_role.as_ref(), authority.key().as_ref(), ac_roles::VAULT_ADMIN], | ||
| seeds::program = AccessControl::id(), | ||
| bump, | ||
| )] | ||
| pub authority_ac_role: Account<'info, AccountAccessControlRoleState>, | ||
|
|
||
| /// Vault minter role | ||
| #[account( | ||
| seeds = [AccountAccessControlRoleState::SEED, token_authority.ac_role.as_ref(), minter_vault.key().as_ref(), ac_roles_token_authority::M_MINTER], | ||
| seeds::program = AccessControl::id(), | ||
| bump, | ||
| )] | ||
| pub vault_minter_role: Account<'info, AccountAccessControlRoleState>, | ||
|
|
||
| /// Minter vault state account | ||
| #[account( | ||
| mut, | ||
| seeds = [MinterVaultState::SEED, vault_common.key().as_ref()], | ||
| bump | ||
| )] | ||
| pub minter_vault: Account<'info, MinterVaultState>, | ||
|
|
||
| /// Mint vault request state account | ||
| #[account( | ||
| mut, | ||
| seeds = [MintVaultRequestState::SEED, minter_vault.key().as_ref(), &request_id.to_le_bytes()], | ||
| bump | ||
| )] | ||
| pub mint_request: Account<'info, MintVaultRequestState>, | ||
|
|
||
| /// Token authority state account (token-authority program) | ||
| #[account( | ||
| mut, | ||
| address = minter_vault.mint_authority_pda, | ||
| owner = TokenAuthority::id() | ||
| )] | ||
| pub token_authority: Account<'info, TokenAuthorityState>, | ||
|
|
||
| /// mMint ATA of `user_account` | ||
| #[account( | ||
| mut, | ||
| associated_token::token_program = m_mint_token_program, | ||
| associated_token::mint = m_mint, | ||
| associated_token::authority = user_account, | ||
| )] | ||
| pub m_mint_user_ata: Box<InterfaceAccount<'info, TokenAccount>>, | ||
|
|
||
| /// SPL mint account | ||
| #[account( | ||
| mut, | ||
| mint::token_program = m_mint_token_program, | ||
| address = vault_common.m_mint | ||
| )] | ||
| pub m_mint: Box<InterfaceAccount<'info, Mint>>, | ||
|
|
||
| /// mMint data feed state account | ||
| #[account( | ||
| address = vault_common.m_mint_feed | ||
| )] | ||
| pub m_mint_data_feed: Account<'info, FeedState>, | ||
|
|
||
| /// CHECK: | ||
| /// mMint underlying feed account | ||
| #[account( | ||
| address = m_mint_data_feed.underlying_feed | ||
| )] | ||
| pub m_mint_feed: AccountInfo<'info>, | ||
|
|
||
| /// SPL token program for mMint | ||
| pub m_mint_token_program: Interface<'info, TokenInterface>, | ||
| /// Token authority program | ||
| pub token_authority_program: Program<'info, TokenAuthority>, | ||
| /// System program | ||
| pub system_program: Program<'info, System>, | ||
| } | ||
|
|
||
| impl<'info> Closable for SafeApproveMintRequestAtCurrentRate<'info> { | ||
| /// close implementation for closing mint request | ||
| /// after it was processed | ||
| fn close(&mut self) -> Result<()> { | ||
| close_account( | ||
| &mut self.mint_request.to_account_info(), | ||
| &mut self.user_account, | ||
| &self.system_program, | ||
| )?; | ||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| /// Safely approves mint request at the current mToken rate from data feed. | ||
| /// Validates variation tolerance between request rate and current rate. | ||
| /// Will close mint request account after processing. | ||
| /// Can only be called by the vault admin. | ||
| /// | ||
| /// # Arguments | ||
| /// | ||
| /// - `request_id` - id of the mint request | ||
| /// - `skip_on_supply_cap_exceeded` - if true, will skip minting and return success | ||
| pub fn handle( | ||
| ctx: Context<SafeApproveMintRequestAtCurrentRate>, | ||
| request_id: u64, | ||
| skip_on_supply_cap_exceeded: bool, | ||
| ) -> Result<()> { | ||
| let current_rate = get_token_rate( | ||
| &ctx.accounts.m_mint_data_feed, | ||
| &ctx.accounts.m_mint_feed, | ||
| false, | ||
| )?; | ||
|
|
||
| match minter::approve_mint_request( | ||
| &ctx.accounts.mint_request, | ||
| &ctx.accounts.vault_common, | ||
| &ctx.accounts.minter_vault, | ||
| &ctx.accounts.m_mint, | ||
| &ctx.accounts.m_mint_user_ata, | ||
| &ctx.accounts.m_mint_token_program, | ||
| &ctx.accounts.user_account, | ||
| &ctx.accounts.token_authority, | ||
| &ctx.accounts.vault_minter_role, | ||
| &ctx.accounts.system_program, | ||
| &ctx.accounts.token_authority_program, | ||
| request_id, | ||
| current_rate, | ||
| true, | ||
| skip_on_supply_cap_exceeded, | ||
| ) { | ||
| Ok(true) => { | ||
| ctx.accounts.close()?; | ||
| Ok(()) | ||
| } | ||
| Ok(false) => Ok(()), | ||
| Err(e) => Err(e), | ||
| } | ||
|
Comment on lines
+149
to
+172
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The if minter::approve_mint_request(
&ctx.accounts.mint_request,
&ctx.accounts.vault_common,
&ctx.accounts.minter_vault,
&ctx.accounts.m_mint,
&ctx.accounts.m_mint_user_ata,
&ctx.accounts.m_mint_token_program,
&ctx.accounts.user_account,
&ctx.accounts.token_authority,
&ctx.accounts.vault_minter_role,
&ctx.accounts.system_program,
&ctx.accounts.token_authority_program,
request_id,
current_rate,
true,
skip_on_supply_cap_exceeded,
)? {
ctx.accounts.close()?;
}
Ok(()) |
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
matchstatement for handling theResult<bool>can be simplified for better readability and conciseness. Usingif letor the?operator is more idiomatic in this case.