generic derivation of health metas

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
microwavedcola1 2022-04-03 20:08:56 +02:00
parent a44120c470
commit 52e2495356
4 changed files with 3168 additions and 3048 deletions

View File

@ -9,7 +9,8 @@ import {
import { MangoClient } from '../../client';
import { debugAccountMetas } from '../../utils';
import bs58 from 'bs58';
import { BorshAccountsCoder } from '@project-serum/anchor';
import { BorshAccountsCoder, ProgramAccount } from '@project-serum/anchor';
import { group } from 'console';
export class Bank {
public depositIndex: I80F48;
@ -197,30 +198,36 @@ export class MintInfo {
constructor(
public publicKey: PublicKey,
mint: PublicKey,
bank: PublicKey,
vault: PublicKey,
oracle: PublicKey,
public mint: PublicKey,
public bank: PublicKey,
public vault: PublicKey,
public oracle: PublicKey,
) {}
}
export async function getMintInfoForTokenIndex(
client: MangoClient,
groupPk: PublicKey,
tokenIndex: number,
): Promise<MintInfo[]> {
const tokenIndexBuf = Buffer.alloc(2);
tokenIndexBuf.writeUInt16LE(tokenIndex);
return (
await client.program.account.mintInfo.all([
{
memcmp: {
bytes: groupPk.toBase58(),
offset: 8,
},
},
{
memcmp: {
bytes: bs58.encode(tokenIndexBuf),
offset: 168,
offset: 200,
},
},
])
).map((tuple) => {
console.log(tuple);
return MintInfo.from(tuple.publicKey, tuple.account);
});
}

View File

@ -105,6 +105,7 @@ export class TokenAccountDto {
}
export class Serum3Account {
static Serum3MarketIndexUnset = 65535;
static from(dto: Serum3AccountDto) {
return new Serum3Account(
dto.openOrders,

View File

@ -31,6 +31,7 @@ import {
getStubOracleForGroupAndMint,
StubOracle,
} from './accounts/types/oracle';
import { assert } from 'console';
async function main() {
//
@ -223,13 +224,44 @@ async function main() {
user.publicKey,
);
const healthRemainingAccounts = [
usdcBank.publicKey,
btcBank.publicKey,
usdcDevnetStubOracle.publicKey,
btcDevnetOracle,
mangoAccount.serum3[0].openOrders,
];
// Aggregate all PKs of users active assets, banks, oracles and serum OOs
const healthRemainingAccounts: PublicKey[] = [];
{
const mintInfos = await Promise.all(
mangoAccount.tokens
.filter((token) => token.tokenIndex !== 65535)
.map(async (token) =>
getMintInfoForTokenIndex(
userClient,
group.publicKey,
token.tokenIndex,
),
),
);
// banks
healthRemainingAccounts.push(
...mintInfos.flatMap((mintinfos) => {
return mintinfos.flatMap((mintinfo) => {
return mintinfo.bank;
});
}),
);
// oracles
healthRemainingAccounts.push(
...mintInfos.flatMap((mintinfos) => {
return mintinfos.flatMap((mintinfo) => {
return mintinfo.oracle;
});
}),
);
// serum OOs
healthRemainingAccounts.push(
...mangoAccount.serum3
.filter((serum3Account) => serum3Account.marketIndex !== 65535)
.map((serum3Account) => serum3Account.openOrders),
);
}
await deposit(
userClient,
group.publicKey,

File diff suppressed because it is too large Load Diff