close insurance vault also
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
parent
0c3efe21a9
commit
91d59c1918
|
@ -1,6 +1,6 @@
|
|||
use crate::state::*;
|
||||
use anchor_lang::prelude::*;
|
||||
use anchor_spl::token::Token;
|
||||
use anchor_spl::token::{self, CloseAccount, Token, TokenAccount};
|
||||
|
||||
#[derive(Accounts)]
|
||||
pub struct GroupClose<'info> {
|
||||
|
@ -8,12 +8,16 @@ pub struct GroupClose<'info> {
|
|||
mut,
|
||||
constraint = group.load()?.testing == 1,
|
||||
has_one = admin,
|
||||
has_one = insurance_vault,
|
||||
close = sol_destination
|
||||
)]
|
||||
pub group: AccountLoader<'info, Group>,
|
||||
|
||||
pub admin: Signer<'info>,
|
||||
|
||||
#[account(mut)]
|
||||
pub insurance_vault: Account<'info, TokenAccount>,
|
||||
|
||||
#[account(mut)]
|
||||
/// CHECK: target for account rent needs no checks
|
||||
pub sol_destination: UncheckedAccount<'info>,
|
||||
|
@ -21,7 +25,24 @@ pub struct GroupClose<'info> {
|
|||
pub token_program: Program<'info, Token>,
|
||||
}
|
||||
|
||||
pub fn group_close(_ctx: Context<GroupClose>) -> Result<()> {
|
||||
pub fn group_close(ctx: Context<GroupClose>) -> Result<()> {
|
||||
// TODO: checks
|
||||
|
||||
// close insurance vault
|
||||
let group = ctx.accounts.group.load()?;
|
||||
let group_seeds = group_seeds!(group);
|
||||
let cpi_accounts = CloseAccount {
|
||||
account: ctx.accounts.insurance_vault.to_account_info(),
|
||||
destination: ctx.accounts.sol_destination.to_account_info(),
|
||||
authority: ctx.accounts.group.to_account_info(),
|
||||
};
|
||||
let cpi_program = ctx.accounts.token_program.to_account_info();
|
||||
token::close_account(CpiContext::new_with_signer(
|
||||
cpi_program,
|
||||
cpi_accounts,
|
||||
&[group_seeds],
|
||||
))?;
|
||||
ctx.accounts.insurance_vault.exit(ctx.program_id)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -1251,7 +1251,6 @@ impl<'keypair> ClientInstruction for GroupCreateInstruction<'keypair> {
|
|||
let accounts = Self::Accounts {
|
||||
group,
|
||||
creator: self.creator.pubkey(),
|
||||
admin: self.creator.pubkey(),
|
||||
insurance_mint: self.insurance_mint,
|
||||
insurance_vault,
|
||||
payer: self.payer.pubkey(),
|
||||
|
@ -1285,9 +1284,16 @@ impl<'keypair> ClientInstruction for GroupCloseInstruction<'keypair> {
|
|||
let program_id = mango_v4::id();
|
||||
let instruction = Self::Instruction {};
|
||||
|
||||
let insurance_vault = Pubkey::find_program_address(
|
||||
&[self.group.as_ref(), b"InsuranceVault".as_ref()],
|
||||
&program_id,
|
||||
)
|
||||
.0;
|
||||
|
||||
let accounts = Self::Accounts {
|
||||
group: self.group,
|
||||
admin: self.admin.pubkey(),
|
||||
insurance_vault,
|
||||
sol_destination: self.sol_destination,
|
||||
token_program: Token::id(),
|
||||
};
|
||||
|
|
|
@ -16,6 +16,8 @@ export class Group {
|
|||
creator: PublicKey;
|
||||
admin: PublicKey;
|
||||
fastListingAdmin: PublicKey;
|
||||
insuranceMint: PublicKey;
|
||||
insuranceVault: PublicKey;
|
||||
groupNum: number;
|
||||
},
|
||||
): Group {
|
||||
|
@ -24,6 +26,8 @@ export class Group {
|
|||
obj.creator,
|
||||
obj.admin,
|
||||
obj.fastListingAdmin,
|
||||
obj.insuranceMint,
|
||||
obj.insuranceVault,
|
||||
obj.groupNum,
|
||||
new Map(),
|
||||
new Map(),
|
||||
|
@ -39,6 +43,8 @@ export class Group {
|
|||
public creator: PublicKey,
|
||||
public admin: PublicKey,
|
||||
public fastListingAdmin: PublicKey,
|
||||
public insuranceMint: PublicKey,
|
||||
public insuranceVault: PublicKey,
|
||||
public groupNum: number,
|
||||
public banksMap: Map<string, Bank>,
|
||||
public serum3MarketsMap: Map<string, Serum3Market>,
|
||||
|
|
|
@ -95,6 +95,7 @@ export class MangoClient {
|
|||
.groupClose()
|
||||
.accounts({
|
||||
group: group.publicKey,
|
||||
insuranceVault: group.insuranceVault,
|
||||
admin: adminPk,
|
||||
solDestination: (this.program.provider as AnchorProvider).wallet
|
||||
.publicKey,
|
||||
|
|
|
@ -41,7 +41,7 @@ export type MangoV4 = {
|
|||
},
|
||||
{
|
||||
"name": "insuranceVault",
|
||||
"isMut": true,
|
||||
"isMut": false,
|
||||
"isSigner": false,
|
||||
"pda": {
|
||||
"seeds": [
|
||||
|
@ -128,6 +128,11 @@ export type MangoV4 = {
|
|||
"isMut": false,
|
||||
"isSigner": true
|
||||
},
|
||||
{
|
||||
"name": "insuranceVault",
|
||||
"isMut": true,
|
||||
"isSigner": false
|
||||
},
|
||||
{
|
||||
"name": "solDestination",
|
||||
"isMut": true,
|
||||
|
@ -4945,7 +4950,7 @@ export const IDL: MangoV4 = {
|
|||
},
|
||||
{
|
||||
"name": "insuranceVault",
|
||||
"isMut": true,
|
||||
"isMut": false,
|
||||
"isSigner": false,
|
||||
"pda": {
|
||||
"seeds": [
|
||||
|
@ -5032,6 +5037,11 @@ export const IDL: MangoV4 = {
|
|||
"isMut": false,
|
||||
"isSigner": true
|
||||
},
|
||||
{
|
||||
"name": "insuranceVault",
|
||||
"isMut": true,
|
||||
"isSigner": false
|
||||
},
|
||||
{
|
||||
"name": "solDestination",
|
||||
"isMut": true,
|
||||
|
|
Loading…
Reference in New Issue