From cc2d46bf4aef45f9a7e831286a28792951d0a777 Mon Sep 17 00:00:00 2001 From: microwavedcola1 Date: Fri, 27 May 2022 14:52:03 +0200 Subject: [PATCH] add support for mint decimals on bank, for easy look up Signed-off-by: microwavedcola1 --- programs/mango-v4/src/instructions/register_token.rs | 1 + programs/mango-v4/src/state/bank.rs | 4 +++- ts/client/src/accounts/bank.ts | 3 +++ ts/client/src/mango_v4.ts | 12 ++++++++++-- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/programs/mango-v4/src/instructions/register_token.rs b/programs/mango-v4/src/instructions/register_token.rs index 4a4544889..f88f15ac4 100644 --- a/programs/mango-v4/src/instructions/register_token.rs +++ b/programs/mango-v4/src/instructions/register_token.rs @@ -131,6 +131,7 @@ pub fn register_token( token_index, bump: *ctx.bumps.get("bank").ok_or(MangoError::SomeError)?, reserved: Default::default(), + mint_decimals: ctx.accounts.mint.decimals, }; // TODO: ALTs are unavailable diff --git a/programs/mango-v4/src/state/bank.rs b/programs/mango-v4/src/state/bank.rs index 1949382d9..2d0b7af76 100644 --- a/programs/mango-v4/src/state/bank.rs +++ b/programs/mango-v4/src/state/bank.rs @@ -61,7 +61,9 @@ pub struct Bank { pub bump: u8, - pub reserved: [u8; 5], + pub mint_decimals: u8, + + pub reserved: [u8; 4], } const_assert_eq!(size_of::(), 16 + 32 * 4 + 8 + 16 * 18 + 3 + 5); const_assert_eq!(size_of::() % 8, 0); diff --git a/ts/client/src/accounts/bank.ts b/ts/client/src/accounts/bank.ts index 537ed8efc..f777a8d50 100644 --- a/ts/client/src/accounts/bank.ts +++ b/ts/client/src/accounts/bank.ts @@ -39,6 +39,7 @@ export class Bank { liquidationFee: I80F48Dto; dust: Object; tokenIndex: number; + mintDecimals: number; }, ) { return new Bank( @@ -68,6 +69,7 @@ export class Bank { obj.liquidationFee, obj.dust, obj.tokenIndex, + obj.mintDecimals, ); } @@ -98,6 +100,7 @@ export class Bank { liquidationFee: I80F48Dto, dust: Object, public tokenIndex: number, + public mintDecimals: number, ) { this.name = utf8.decode(new Uint8Array(name)).split('\x00')[0]; this.depositIndex = I80F48.from(depositIndex); diff --git a/ts/client/src/mango_v4.ts b/ts/client/src/mango_v4.ts index 82b141a22..36ccd3fb7 100644 --- a/ts/client/src/mango_v4.ts +++ b/ts/client/src/mango_v4.ts @@ -1730,12 +1730,16 @@ export type MangoV4 = { "name": "bump", "type": "u8" }, + { + "name": "mintDecimals", + "type": "u8" + }, { "name": "reserved", "type": { "array": [ "u8", - 5 + 4 ] } } @@ -4626,12 +4630,16 @@ export const IDL: MangoV4 = { "name": "bump", "type": "u8" }, + { + "name": "mintDecimals", + "type": "u8" + }, { "name": "reserved", "type": { "array": [ "u8", - 5 + 4 ] } }