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

View File

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

View File

@ -31,6 +31,7 @@ import {
getStubOracleForGroupAndMint, getStubOracleForGroupAndMint,
StubOracle, StubOracle,
} from './accounts/types/oracle'; } from './accounts/types/oracle';
import { assert } from 'console';
async function main() { async function main() {
// //
@ -223,13 +224,44 @@ async function main() {
user.publicKey, user.publicKey,
); );
const healthRemainingAccounts = [ // Aggregate all PKs of users active assets, banks, oracles and serum OOs
usdcBank.publicKey, const healthRemainingAccounts: PublicKey[] = [];
btcBank.publicKey, {
usdcDevnetStubOracle.publicKey, const mintInfos = await Promise.all(
btcDevnetOracle, mangoAccount.tokens
mangoAccount.serum3[0].openOrders, .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( await deposit(
userClient, userClient,
group.publicKey, group.publicKey,

File diff suppressed because it is too large Load Diff