Added new parseTokenAccount

This commit is contained in:
dd 2021-04-07 09:09:54 -04:00
parent e581b5dfc7
commit f78266cbc2
2 changed files with 28 additions and 0 deletions

View File

@ -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);
}

View File

@ -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[]