diff --git a/src/layout.ts b/src/layout.ts index c8f7cc8..8d608c5 100644 --- a/src/layout.ts +++ b/src/layout.ts @@ -166,6 +166,19 @@ export const MangoSrmAccountLayout = struct([ u64('amount') ]); +export const AccountLayout = struct([ + publicKeyLayout('mint'), + publicKeyLayout('owner'), + u64('amount'), + u32('delegateOption'), + publicKeyLayout('delegate'), + u8('state'), + u32('isNativeOption'), + u64('isNative'), + u64('delegatedAmount'), + u32('closeAuthorityOption'), + publicKeyLayout('closeAuthority') +]); class EnumLayout extends UInt { values: any; @@ -271,3 +284,5 @@ export function encodeMangoInstruction(data) { const span = MangoInstructionLayout.encode(data, b); return b.slice(0, span); } + + diff --git a/src/utils.ts b/src/utils.ts index e3affa0..183456a 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -11,6 +11,7 @@ import BN from 'bn.js'; import { WRAPPED_SOL_MINT } from '@project-serum/serum/lib/token-instructions'; import { blob, struct, u8, nu64 } from 'buffer-layout'; import { TOKEN_PROGRAM_ID } from '@solana/spl-token'; +import { AccountLayout } from './layout'; export const zeroKey = new PublicKey(new Uint8Array(32)) @@ -230,6 +231,18 @@ export function parseTokenAccountData( }; } +export function parseTokenAccount( + data: Buffer +): { mint: PublicKey; owner: PublicKey; amount: BN } { + + const decoded = AccountLayout.decode(data) + return { + mint: decoded.mint, + owner: decoded.owner, + amount: decoded.amount + } +} + export async function getMultipleAccounts( connection: Connection, publicKeys: PublicKey[]