token_deregister: remove redundant token index and add doc (#192)

* token_deregister: remove redundant token index

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

* fix test

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
microwavedcola1 2022-08-25 19:25:56 +02:00 committed by GitHub
parent 3a1fc2b271
commit 453248bbe5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 8 additions and 22 deletions

View File

@ -4,8 +4,9 @@ use anchor_spl::token::{self, CloseAccount, Token, TokenAccount};
use crate::{accounts_zerocopy::LoadZeroCopyRef, state::*}; use crate::{accounts_zerocopy::LoadZeroCopyRef, state::*};
use anchor_lang::AccountsClose; use anchor_lang::AccountsClose;
/// In addition to these accounts, there must be remaining_accounts:
/// all n pairs of bank and its corresponding vault account for a token
#[derive(Accounts)] #[derive(Accounts)]
#[instruction(token_index: TokenIndex)]
pub struct TokenDeregister<'info> { pub struct TokenDeregister<'info> {
#[account( #[account(
constraint = group.load()?.is_testing(), constraint = group.load()?.is_testing(),
@ -18,7 +19,6 @@ pub struct TokenDeregister<'info> {
#[account( #[account(
mut, mut,
has_one = group, has_one = group,
constraint = mint_info.load()?.token_index == token_index,
close = sol_destination close = sol_destination
)] )]
pub mint_info: AccountLoader<'info, MintInfo>, pub mint_info: AccountLoader<'info, MintInfo>,
@ -36,7 +36,6 @@ pub struct TokenDeregister<'info> {
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub fn token_deregister<'key, 'accounts, 'remaining, 'info>( pub fn token_deregister<'key, 'accounts, 'remaining, 'info>(
ctx: Context<'key, 'accounts, 'remaining, 'info, TokenDeregister<'info>>, ctx: Context<'key, 'accounts, 'remaining, 'info, TokenDeregister<'info>>,
token_index: TokenIndex,
) -> Result<()> { ) -> Result<()> {
let mint_info = ctx.accounts.mint_info.load()?; let mint_info = ctx.accounts.mint_info.load()?;
{ {
@ -61,7 +60,7 @@ pub fn token_deregister<'key, 'accounts, 'remaining, 'info>(
{ {
let bank = bank_ai.load::<Bank>()?; let bank = bank_ai.load::<Bank>()?;
require_keys_eq!(bank.group, ctx.accounts.group.key()); require_keys_eq!(bank.group, ctx.accounts.group.key());
require_eq!(bank.token_index, token_index); require_eq!(bank.token_index, mint_info.token_index);
require_keys_eq!(bank.vault, vault_ai.key()); require_keys_eq!(bank.vault, vault_ai.key());
} }

View File

@ -142,9 +142,8 @@ pub mod mango_v4 {
pub fn token_deregister<'key, 'accounts, 'remaining, 'info>( pub fn token_deregister<'key, 'accounts, 'remaining, 'info>(
ctx: Context<'key, 'accounts, 'remaining, 'info, TokenDeregister<'info>>, ctx: Context<'key, 'accounts, 'remaining, 'info, TokenDeregister<'info>>,
token_index: TokenIndex,
) -> Result<()> { ) -> Result<()> {
instructions::token_deregister(ctx, token_index) instructions::token_deregister(ctx)
} }
pub fn token_update_index_and_rate(ctx: Context<TokenUpdateIndexAndRate>) -> Result<()> { pub fn token_update_index_and_rate(ctx: Context<TokenUpdateIndexAndRate>) -> Result<()> {

View File

@ -836,9 +836,7 @@ impl<'keypair> ClientInstruction for TokenDeregisterInstruction<'keypair> {
_loader: impl ClientAccountLoader + 'async_trait, _loader: impl ClientAccountLoader + 'async_trait,
) -> (Self::Accounts, Instruction) { ) -> (Self::Accounts, Instruction) {
let program_id = mango_v4::id(); let program_id = mango_v4::id();
let instruction = Self::Instruction { let instruction = Self::Instruction {};
token_index: self.token_index,
};
let accounts = Self::Accounts { let accounts = Self::Accounts {
admin: self.admin.pubkey(), admin: self.admin.pubkey(),

View File

@ -348,7 +348,7 @@ export class MangoClient {
} }
return await this.program.methods return await this.program.methods
.tokenDeregister(bank.tokenIndex) .tokenDeregister()
.accounts({ .accounts({
group: group.publicKey, group: group.publicKey,
admin: adminPk, admin: adminPk,

View File

@ -730,12 +730,7 @@ export type MangoV4 = {
"isSigner": false "isSigner": false
} }
], ],
"args": [ "args": []
{
"name": "tokenIndex",
"type": "u16"
}
]
}, },
{ {
"name": "tokenUpdateIndexAndRate", "name": "tokenUpdateIndexAndRate",
@ -5984,12 +5979,7 @@ export const IDL: MangoV4 = {
"isSigner": false "isSigner": false
} }
], ],
"args": [ "args": []
{
"name": "tokenIndex",
"type": "u16"
}
]
}, },
{ {
"name": "tokenUpdateIndexAndRate", "name": "tokenUpdateIndexAndRate",