generic derivation of health metas
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
parent
a44120c470
commit
52e2495356
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -105,6 +105,7 @@ export class TokenAccountDto {
|
|||
}
|
||||
|
||||
export class Serum3Account {
|
||||
static Serum3MarketIndexUnset = 65535;
|
||||
static from(dto: Serum3AccountDto) {
|
||||
return new Serum3Account(
|
||||
dto.openOrders,
|
||||
|
|
|
@ -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,
|
||||
|
|
6148
ts/mango_v4.ts
6148
ts/mango_v4.ts
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue