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 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)]
#[instruction(token_index: TokenIndex)]
pub struct TokenDeregister<'info> {
#[account(
constraint = group.load()?.is_testing(),
@ -18,7 +19,6 @@ pub struct TokenDeregister<'info> {
#[account(
mut,
has_one = group,
constraint = mint_info.load()?.token_index == token_index,
close = sol_destination
)]
pub mint_info: AccountLoader<'info, MintInfo>,
@ -36,7 +36,6 @@ pub struct TokenDeregister<'info> {
#[allow(clippy::too_many_arguments)]
pub fn token_deregister<'key, 'accounts, 'remaining, 'info>(
ctx: Context<'key, 'accounts, 'remaining, 'info, TokenDeregister<'info>>,
token_index: TokenIndex,
) -> Result<()> {
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>()?;
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());
}

View File

@ -142,9 +142,8 @@ pub mod mango_v4 {
pub fn token_deregister<'key, 'accounts, 'remaining, 'info>(
ctx: Context<'key, 'accounts, 'remaining, 'info, TokenDeregister<'info>>,
token_index: TokenIndex,
) -> Result<()> {
instructions::token_deregister(ctx, token_index)
instructions::token_deregister(ctx)
}
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,
) -> (Self::Accounts, Instruction) {
let program_id = mango_v4::id();
let instruction = Self::Instruction {
token_index: self.token_index,
};
let instruction = Self::Instruction {};
let accounts = Self::Accounts {
admin: self.admin.pubkey(),

View File

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

View File

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