support name edit for token and program (#488)

* support name edit for token and program

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

* undo

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

* Fixes from review

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

---------

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
microwavedcola1 2023-03-03 10:05:12 +01:00 committed by GitHub
parent f29fffd331
commit 1950d8c84a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 52 additions and 0 deletions

View File

@ -1,3 +1,4 @@
use crate::util::fill_from_str;
use crate::{accounts_zerocopy::AccountInfoRef, error::MangoError, state::*};
use anchor_lang::prelude::*;
use fixed::types::I80F48;
@ -36,6 +37,7 @@ pub fn perp_edit_market(
reduce_only_opt: Option<bool>,
reset_stable_price: bool,
positive_pnl_liquidation_fee_opt: Option<f32>,
name_opt: Option<String>,
) -> Result<()> {
let group = ctx.accounts.group.load()?;
@ -322,6 +324,12 @@ pub fn perp_edit_market(
require_group_admin = true;
}
if let Some(name) = name_opt.as_ref() {
msg!("Name: old - {:?}, new - {:?}", perp_market.name, name);
perp_market.name = fill_from_str(&name)?;
require_group_admin = true;
};
// account constraint #1
if require_group_admin {
require!(

View File

@ -9,6 +9,7 @@ use crate::state::*;
use crate::accounts_ix::*;
use crate::logs::TokenMetaDataLog;
use crate::util::fill_from_str;
#[allow(unused_variables)]
#[allow(clippy::too_many_arguments)]
@ -36,6 +37,7 @@ pub fn token_edit(
reset_stable_price: bool,
reset_net_borrow_limit: bool,
reduce_only_opt: Option<bool>,
name_opt: Option<String>,
) -> Result<()> {
let group = ctx.accounts.group.load()?;
@ -281,6 +283,12 @@ pub fn token_edit(
require_group_admin = true;
}
};
if let Some(name) = name_opt.as_ref() {
msg!("Name: old - {:?}, new - {:?}", bank.name, name);
bank.name = fill_from_str(&name)?;
require_group_admin = true;
};
}
// account constraint #1

View File

@ -170,6 +170,7 @@ pub mod mango_v4 {
reset_stable_price: bool,
reset_net_borrow_limit: bool,
reduce_only_opt: Option<bool>,
name_opt: Option<String>,
) -> Result<()> {
#[cfg(feature = "enable-gpl")]
instructions::token_edit(
@ -196,6 +197,7 @@ pub mod mango_v4 {
reset_stable_price,
reset_net_borrow_limit,
reduce_only_opt,
name_opt,
)?;
Ok(())
}
@ -629,6 +631,7 @@ pub mod mango_v4 {
reduce_only_opt: Option<bool>,
reset_stable_price: bool,
positive_pnl_liquidation_fee_opt: Option<f32>,
name_opt: Option<String>,
) -> Result<()> {
#[cfg(feature = "enable-gpl")]
instructions::perp_edit_market(
@ -661,6 +664,7 @@ pub mod mango_v4 {
reduce_only_opt,
reset_stable_price,
positive_pnl_liquidation_fee_opt,
name_opt,
)?;
Ok(())
}

View File

@ -1071,6 +1071,7 @@ fn token_edit_instruction_default() -> mango_v4::instruction::TokenEdit {
reset_stable_price: false,
reset_net_borrow_limit: false,
reduce_only_opt: None,
name_opt: None,
}
}
@ -2820,6 +2821,7 @@ fn perp_edit_instruction_default() -> mango_v4::instruction::PerpEditMarket {
reduce_only_opt: None,
reset_stable_price: false,
positive_pnl_liquidation_fee_opt: None,
name_opt: None,
}
}

View File

@ -384,6 +384,7 @@ export class MangoClient {
params.resetStablePrice ?? false,
params.resetNetBorrowLimit ?? false,
params.reduceOnly,
params.name,
)
.accounts({
group: group.publicKey,
@ -1916,6 +1917,7 @@ export class MangoClient {
params.reduceOnly,
params.resetStablePrice ?? false,
params.positivePnlLiquidationFee,
params.name,
)
.accounts({
group: group.publicKey,

View File

@ -25,6 +25,7 @@ export interface TokenEditParams {
resetStablePrice: boolean | null;
resetNetBorrowLimit: boolean | null;
reduceOnly: boolean | null;
name: string | null;
}
export const NullTokenEditParams: TokenEditParams = {
@ -50,6 +51,7 @@ export const NullTokenEditParams: TokenEditParams = {
resetStablePrice: null,
resetNetBorrowLimit: null,
reduceOnly: null,
name: null,
};
export interface PerpEditParams {
@ -81,6 +83,7 @@ export interface PerpEditParams {
reduceOnly: boolean | null;
resetStablePrice: boolean | null;
positivePnlLiquidationFee: number | null;
name: string | null;
}
export const NullPerpEditParams: PerpEditParams = {
@ -112,6 +115,7 @@ export const NullPerpEditParams: PerpEditParams = {
reduceOnly: null,
resetStablePrice: null,
positivePnlLiquidationFee: null,
name: null,
};
// Use with TrueIxGateParams and buildIxGate

View File

@ -717,6 +717,12 @@ export type MangoV4 = {
"type": {
"option": "bool"
}
},
{
"name": "nameOpt",
"type": {
"option": "string"
}
}
]
},
@ -2885,6 +2891,12 @@ export type MangoV4 = {
"type": {
"option": "f32"
}
},
{
"name": "nameOpt",
"type": {
"option": "string"
}
}
]
},
@ -9200,6 +9212,12 @@ export const IDL: MangoV4 = {
"type": {
"option": "bool"
}
},
{
"name": "nameOpt",
"type": {
"option": "string"
}
}
]
},
@ -11368,6 +11386,12 @@ export const IDL: MangoV4 = {
"type": {
"option": "f32"
}
},
{
"name": "nameOpt",
"type": {
"option": "string"
}
}
]
},