Skip to content

Commit

Permalink
Merge pull request #209 from blockworks-foundation/v3-recovery
Browse files Browse the repository at this point in the history
Allow recovery of funds from mainnet.1 group
  • Loading branch information
riordanp authored Oct 20, 2022
2 parents 4197d0d + e02a079 commit 43aab1f
Show file tree
Hide file tree
Showing 3 changed files with 960 additions and 547 deletions.
17 changes: 17 additions & 0 deletions program/src/ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,20 @@ pub mod luna_pyth_oracle {
use solana_program::declare_id;
declare_id!("5bmWuR1dgP4avtGYMNKLuxumZTVKGgoN2BCMXWDNL9nY");
}

pub mod mainnet_1_group {
use solana_program::declare_id;
#[cfg(feature = "devnet")]
declare_id!("Ec2enZyoC4nGpEfu2sUNAa2nUGJHWxoUWYSEJ2hNTWTA");
#[cfg(not(feature = "devnet"))]
declare_id!("98pjRuQjK3qA6gXts96PqZT4Ze5QmnCmt3QYjhbUSPue");
}

// Owner of the reimbursement fund multisig accounts
pub mod recovery_authority {
use solana_program::declare_id;
#[cfg(feature = "devnet")]
declare_id!("8pANRWCcw8vn8DszUP7hh4xFbCiBiMWX3WbwUTipArSJ");
#[cfg(not(feature = "devnet"))]
declare_id!("9mM6NfXauEFviFY1S1thbo7HXYNiSWSvwZEhguJw26wY");
}
66 changes: 66 additions & 0 deletions program/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,62 @@ pub enum MangoInstruction {
ref_mngo_required: u64,
ref_mngo_tier_2_factor: u8,
},

/// Force cancellation and settlement of open orders for a user in a recovery group
///
/// Accounts expected: 18 + open orders accounts (MAX_PAIRS)
/// 0. `[]` mango_group_ai - MangoGroup
/// 1. `[writable]` mango_account_ai - MangoAccount
/// 2. `[]` base_root_bank_ai - RootBank
/// 3. `[writable]` base_node_bank_ai - NodeBank
/// 4. `[writable]` base_vault_ai - MangoGroup base vault acc
/// 5. `[]` quote_root_bank_ai - RootBank
/// 6. `[writable]` quote_node_bank_ai - NodeBank
/// 7. `[writable]` quote_vault_ai - MangoGroup quote vault acc
/// 8. `[writable]` spot_market_ai - SpotMarket
/// 9. `[writable]` bids_ai - SpotMarket bids acc
/// 10. `[writable]` asks_ai - SpotMarket asks acc
/// 12. `[signer]` signer_ai - Signer
/// 12. `[writable]` dex_event_queue_ai - Market event queue acc
/// 13. `[writable]` dex_base_ai -
/// 14. `[writable]` dex_quote_ai -
/// 15. `[]` dex_signer_ai -
/// 16. `[]` dex_prog_ai - Dex Program acc
/// 17. `[]` token_prog_ai - Token Program acc
/// 18+... `[]` open_orders_ais - open orders accs
RecoveryForceSettleSpotOrders {
limit: u8,
},

/// Allow withdrawal of token accounts in a recovery group
/// Accounts expected: 6
/// 0. `[]` mango_group_ai - MangoGroup
/// 1. `[writable]` vault_ai - Vault TokenAccount
/// 2. `[writable]` token_account_ai - Recovery authority ata
/// 3. `[]` root_bank_ai - RootBank
/// 4. `[]` node_bank_ai - NodeBank
/// 5. `[]` signer_ai - Group Signer Key
/// 6. `[]` token_prog_ai - Token program
RecoveryWithdrawTokenVault,

/// Allow withdrawal of unused mngo rewards in a recovery group
/// Accounts expected: 5
/// 0. `[]` mango_group_ai - MangoGroup
/// 1. `[writable]` vault_ai - Vault TokenAccount
/// 2. `[writable]` token_account_ai - Recovery authority MNGO ata
// 3. `[]` perp_market_ai - Perp market
/// 4. `[]` signer_ai - Group Signer Key
/// 5. `[]` token_prog_ai - Token program
RecoveryWithdrawMngoVault,

/// Allow withdrawal of the insurance vault in a recovery group
/// Accounts expected: 4
/// 0. `[]` mango_group_ai - MangoGroup
/// 1. `[writable]` vault_ai - Vault TokenAccount
/// 2. `[writable]` token_account_ai - Recovery authority USDC ata
/// 3. `[]` signer_ai - Group Signer Key
/// 4. `[]` token_prog_ai - Token program
RecoveryWithdrawInsuranceVault,
}

impl MangoInstruction {
Expand Down Expand Up @@ -1745,6 +1801,16 @@ impl MangoInstruction {
ref_mngo_tier_2_factor: u8::from_le_bytes(*ref_mngo_tier_2_factor),
}
}
75 => {
let data_arr = array_ref![data, 0, 1];

MangoInstruction::RecoveryForceSettleSpotOrders {
limit: u8::from_le_bytes(*data_arr),
}
}
76 => MangoInstruction::RecoveryWithdrawTokenVault,
77 => MangoInstruction::RecoveryWithdrawMngoVault,
78 => MangoInstruction::RecoveryWithdrawInsuranceVault,
_ => {
return None;
}
Expand Down
Loading

0 comments on commit 43aab1f

Please sign in to comment.