prepare group for ownership transfer to governance (#125)
* prepare group for ownership transfer to governance Signed-off-by: microwavedcola1 <microwavedcola@gmail.com> * Fixes from reviews Signed-off-by: microwavedcola1 <microwavedcola@gmail.com> * fix from review Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
parent
c88297f42e
commit
45fd36642e
|
@ -9,14 +9,14 @@ use crate::state::*;
|
||||||
pub struct GroupCreate<'info> {
|
pub struct GroupCreate<'info> {
|
||||||
#[account(
|
#[account(
|
||||||
init,
|
init,
|
||||||
seeds = [b"Group".as_ref(), admin.key().as_ref(), &group_num.to_le_bytes()],
|
seeds = [b"Group".as_ref(), creator.key().as_ref(), &group_num.to_le_bytes()],
|
||||||
bump,
|
bump,
|
||||||
payer = payer,
|
payer = payer,
|
||||||
space = 8 + std::mem::size_of::<Group>(),
|
space = 8 + std::mem::size_of::<Group>(),
|
||||||
)]
|
)]
|
||||||
pub group: AccountLoader<'info, Group>,
|
pub group: AccountLoader<'info, Group>,
|
||||||
|
|
||||||
pub admin: Signer<'info>,
|
pub creator: Signer<'info>,
|
||||||
|
|
||||||
pub insurance_mint: Account<'info, Mint>,
|
pub insurance_mint: Account<'info, Mint>,
|
||||||
|
|
||||||
|
@ -40,7 +40,9 @@ pub struct GroupCreate<'info> {
|
||||||
|
|
||||||
pub fn group_create(ctx: Context<GroupCreate>, group_num: u32, testing: u8) -> Result<()> {
|
pub fn group_create(ctx: Context<GroupCreate>, group_num: u32, testing: u8) -> Result<()> {
|
||||||
let mut group = ctx.accounts.group.load_init()?;
|
let mut group = ctx.accounts.group.load_init()?;
|
||||||
group.admin = ctx.accounts.admin.key();
|
group.creator = ctx.accounts.creator.key();
|
||||||
|
group.admin = ctx.accounts.creator.key();
|
||||||
|
group.fast_listing_admin = Pubkey::default();
|
||||||
group.insurance_vault = ctx.accounts.insurance_vault.key();
|
group.insurance_vault = ctx.accounts.insurance_vault.key();
|
||||||
group.insurance_mint = ctx.accounts.insurance_mint.key();
|
group.insurance_mint = ctx.accounts.insurance_mint.key();
|
||||||
group.bump = *ctx.bumps.get("group").ok_or(MangoError::SomeError)?;
|
group.bump = *ctx.bumps.get("group").ok_or(MangoError::SomeError)?;
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
use anchor_lang::prelude::*;
|
||||||
|
|
||||||
|
use crate::state::*;
|
||||||
|
|
||||||
|
#[derive(Accounts)]
|
||||||
|
pub struct GroupEdit<'info> {
|
||||||
|
#[account(
|
||||||
|
mut,
|
||||||
|
has_one = admin,
|
||||||
|
)]
|
||||||
|
pub group: AccountLoader<'info, Group>,
|
||||||
|
pub admin: Signer<'info>,
|
||||||
|
}
|
||||||
|
|
||||||
|
// use case - transfer group ownership to governance, where
|
||||||
|
// new_admin and new_fast_listing_admin are PDAs
|
||||||
|
pub fn group_edit(
|
||||||
|
ctx: Context<GroupEdit>,
|
||||||
|
new_admin: Pubkey,
|
||||||
|
new_fast_listing_admin: Pubkey,
|
||||||
|
) -> Result<()> {
|
||||||
|
let mut group = ctx.accounts.group.load_mut()?;
|
||||||
|
group.admin = new_admin;
|
||||||
|
group.fast_listing_admin = new_fast_listing_admin;
|
||||||
|
Ok(())
|
||||||
|
}
|
|
@ -9,6 +9,7 @@ pub use flash_loan2::*;
|
||||||
pub use flash_loan3::*;
|
pub use flash_loan3::*;
|
||||||
pub use group_close::*;
|
pub use group_close::*;
|
||||||
pub use group_create::*;
|
pub use group_create::*;
|
||||||
|
pub use group_edit::*;
|
||||||
pub use liq_token_bankruptcy::*;
|
pub use liq_token_bankruptcy::*;
|
||||||
pub use liq_token_with_token::*;
|
pub use liq_token_with_token::*;
|
||||||
pub use perp_cancel_all_orders::*;
|
pub use perp_cancel_all_orders::*;
|
||||||
|
@ -52,6 +53,7 @@ mod flash_loan2;
|
||||||
mod flash_loan3;
|
mod flash_loan3;
|
||||||
mod group_close;
|
mod group_close;
|
||||||
mod group_create;
|
mod group_create;
|
||||||
|
mod group_edit;
|
||||||
mod liq_token_bankruptcy;
|
mod liq_token_bankruptcy;
|
||||||
mod liq_token_with_token;
|
mod liq_token_with_token;
|
||||||
mod perp_cancel_all_orders;
|
mod perp_cancel_all_orders;
|
||||||
|
|
|
@ -36,6 +36,14 @@ pub mod mango_v4 {
|
||||||
instructions::group_create(ctx, group_num, testing)
|
instructions::group_create(ctx, group_num, testing)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn group_edit(
|
||||||
|
ctx: Context<GroupEdit>,
|
||||||
|
new_admin: Pubkey,
|
||||||
|
new_fast_listing_admin: Pubkey,
|
||||||
|
) -> Result<()> {
|
||||||
|
instructions::group_edit(ctx, new_admin, new_fast_listing_admin)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn group_close(ctx: Context<GroupClose>) -> Result<()> {
|
pub fn group_close(ctx: Context<GroupClose>) -> Result<()> {
|
||||||
instructions::group_close(ctx)
|
instructions::group_close(ctx)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,11 +10,16 @@ pub const QUOTE_TOKEN_INDEX: TokenIndex = 0;
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Group {
|
pub struct Group {
|
||||||
// ABI: Clients rely on this being at offset 8
|
// ABI: Clients rely on this being at offset 8
|
||||||
pub admin: Pubkey,
|
pub creator: Pubkey,
|
||||||
|
|
||||||
// ABI: Clients rely on this being at offset 40
|
// ABI: Clients rely on this being at offset 40
|
||||||
pub group_num: u32,
|
pub group_num: u32,
|
||||||
|
|
||||||
|
pub admin: Pubkey,
|
||||||
|
|
||||||
|
// TODO: unused, use case - listing shit tokens with conservative parameters (mostly defaults)
|
||||||
|
pub fast_listing_admin: Pubkey,
|
||||||
|
|
||||||
pub padding: [u8; 4],
|
pub padding: [u8; 4],
|
||||||
|
|
||||||
pub insurance_vault: Pubkey,
|
pub insurance_vault: Pubkey,
|
||||||
|
@ -27,15 +32,16 @@ pub struct Group {
|
||||||
pub padding2: [u8; 6],
|
pub padding2: [u8; 6],
|
||||||
pub reserved: [u8; 8],
|
pub reserved: [u8; 8],
|
||||||
}
|
}
|
||||||
const_assert_eq!(size_of::<Group>(), 32 * 3 + 4 + 4 + 1 * 2 + 6 + 8);
|
const_assert_eq!(size_of::<Group>(), 32 * 5 + 4 + 4 + 1 * 2 + 6 + 8);
|
||||||
const_assert_eq!(size_of::<Group>() % 8, 0);
|
const_assert_eq!(size_of::<Group>() % 8, 0);
|
||||||
|
|
||||||
|
// note: using creator instead of admin, since admin can be changed
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! group_seeds {
|
macro_rules! group_seeds {
|
||||||
( $group:expr ) => {
|
( $group:expr ) => {
|
||||||
&[
|
&[
|
||||||
b"Group".as_ref(),
|
b"Group".as_ref(),
|
||||||
$group.admin.as_ref(),
|
$group.creator.as_ref(),
|
||||||
&$group.group_num.to_le_bytes(),
|
&$group.group_num.to_le_bytes(),
|
||||||
&[$group.bump],
|
&[$group.bump],
|
||||||
]
|
]
|
||||||
|
|
|
@ -1214,7 +1214,7 @@ impl<'keypair> ClientInstruction for StubOracleCloseInstruction<'keypair> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct GroupCreateInstruction<'keypair> {
|
pub struct GroupCreateInstruction<'keypair> {
|
||||||
pub admin: &'keypair Keypair,
|
pub creator: &'keypair Keypair,
|
||||||
pub payer: &'keypair Keypair,
|
pub payer: &'keypair Keypair,
|
||||||
pub insurance_mint: Pubkey,
|
pub insurance_mint: Pubkey,
|
||||||
}
|
}
|
||||||
|
@ -1235,7 +1235,7 @@ impl<'keypair> ClientInstruction for GroupCreateInstruction<'keypair> {
|
||||||
let group = Pubkey::find_program_address(
|
let group = Pubkey::find_program_address(
|
||||||
&[
|
&[
|
||||||
b"Group".as_ref(),
|
b"Group".as_ref(),
|
||||||
self.admin.pubkey().as_ref(),
|
self.creator.pubkey().as_ref(),
|
||||||
&instruction.group_num.to_le_bytes(),
|
&instruction.group_num.to_le_bytes(),
|
||||||
],
|
],
|
||||||
&program_id,
|
&program_id,
|
||||||
|
@ -1250,7 +1250,8 @@ impl<'keypair> ClientInstruction for GroupCreateInstruction<'keypair> {
|
||||||
|
|
||||||
let accounts = Self::Accounts {
|
let accounts = Self::Accounts {
|
||||||
group,
|
group,
|
||||||
admin: self.admin.pubkey(),
|
creator: self.creator.pubkey(),
|
||||||
|
admin: self.creator.pubkey(),
|
||||||
insurance_mint: self.insurance_mint,
|
insurance_mint: self.insurance_mint,
|
||||||
insurance_vault,
|
insurance_vault,
|
||||||
payer: self.payer.pubkey(),
|
payer: self.payer.pubkey(),
|
||||||
|
@ -1264,7 +1265,7 @@ impl<'keypair> ClientInstruction for GroupCreateInstruction<'keypair> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn signers(&self) -> Vec<&Keypair> {
|
fn signers(&self) -> Vec<&Keypair> {
|
||||||
vec![self.admin, self.payer]
|
vec![self.creator, self.payer]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ impl<'a> GroupWithTokensConfig<'a> {
|
||||||
let create_group_accounts = send_tx(
|
let create_group_accounts = send_tx(
|
||||||
solana,
|
solana,
|
||||||
GroupCreateInstruction {
|
GroupCreateInstruction {
|
||||||
admin,
|
creator: admin,
|
||||||
payer,
|
payer,
|
||||||
insurance_mint: mints[0].pubkey,
|
insurance_mint: mints[0].pubkey,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue