mintinfo support

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
microwavedcola1 2022-04-03 17:26:45 +02:00
parent 7748147737
commit 897260f7c7
2 changed files with 52 additions and 0 deletions

View File

@ -8,6 +8,8 @@ import {
} from '@solana/web3.js';
import { MangoClient } from '../../client';
import { debugAccountMetas } from '../../utils';
import bs58 from 'bs58';
import { BorshAccountsCoder } from '@project-serum/anchor';
export class Bank {
public depositIndex: I80F48;
@ -174,3 +176,51 @@ export async function getBankForGroupAndMint(
])
).map((tuple) => Bank.from(tuple.publicKey, tuple.account));
}
export class MintInfo {
static from(
publicKey: PublicKey,
obj: {
mint: PublicKey;
bank: PublicKey;
vault: PublicKey;
oracle: PublicKey;
addressLookupTable: PublicKey;
tokenIndex: Number;
addressLookupTableBankIndex: Number;
addressLookupTableOracleIndex: Number;
reserved: unknown;
},
) {
return new MintInfo(publicKey, obj.mint, obj.bank, obj.vault, obj.oracle);
}
constructor(
public publicKey: PublicKey,
mint: PublicKey,
bank: PublicKey,
vault: PublicKey,
oracle: PublicKey,
) {}
}
export async function getMintInfoForTokenIndex(
client: MangoClient,
tokenIndex: number,
): Promise<MintInfo[]> {
const tokenIndexBuf = Buffer.alloc(2);
tokenIndexBuf.writeUInt16LE(tokenIndex);
return (
await client.program.account.mintInfo.all([
{
memcmp: {
bytes: bs58.encode(tokenIndexBuf),
offset: 168,
},
},
])
).map((tuple) => {
console.log(tuple);
return MintInfo.from(tuple.publicKey, tuple.account);
});
}

View File

@ -8,6 +8,7 @@ import {
Bank,
getBank,
getBankForGroupAndMint,
getMintInfoForTokenIndex,
registerToken,
} from './accounts/types/bank';
import {
@ -221,6 +222,7 @@ async function main() {
btcDevnetMint,
user.publicKey,
);
const healthRemainingAccounts = [
usdcBank.publicKey,
btcBank.publicKey,