error for debugging banks

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
microwavedcola1 2022-08-15 19:13:18 +02:00
parent 24524d7cd5
commit 03dbac82f9
1 changed files with 21 additions and 9 deletions

View File

@ -2,7 +2,7 @@ import { AnchorProvider, Wallet } from '@project-serum/anchor';
import { coder } from '@project-serum/anchor/dist/cjs/spl/token';
import { Connection, Keypair } from '@solana/web3.js';
import fs from 'fs';
import { ZERO_I80F48 } from '../accounts/I80F48';
import { I80F48, ZERO_I80F48 } from '../accounts/I80F48';
import { MangoClient } from '../client';
import { MANGO_V4_ID } from '../constants';
@ -69,9 +69,28 @@ async function main() {
for (const bank of await Array.from(banksMapUsingTokenIndex.values()).sort(
(a, b) => a.tokenIndex - b.tokenIndex,
)) {
const vault = I80F48.fromNumber(
coder()
.accounts.decode(
'token',
await (
await client.program.provider.connection.getAccountInfo(bank.vault)
).data,
)
.amount.toNumber(),
);
const error = vault.sub(
(bank as any).indexedDepositsByMangoAccounts
.sub((bank as any).indexedBorrowsByMangoAccounts)
.add(bank.collectedFeesNative)
.add(bank.dust),
);
let res = `${bank.name}`;
res =
res +
`\n ${'error'.padEnd(40)} ${error}` +
`\n ${'collectedFeesNative'.padEnd(40)} ${bank.collectedFeesNative}` +
`\n ${'dust'.padEnd(40)} ${bank.dust}` +
`\n ${'deposits'.padEnd(40)} ${bank.indexedDeposits.mul(
@ -95,14 +114,7 @@ async function main() {
`\n ${'avgUtilization'.padEnd(40)} ${bank.avgUtilization}` +
`\n ${'depositRate'.padEnd(40)} ${bank.getDepositRate()}` +
`\n ${'borrowRate'.padEnd(40)} ${bank.getBorrowRate()}` +
`\n ${'vault'.padEnd(40)} ${coder()
.accounts.decode(
'token',
await (
await client.program.provider.connection.getAccountInfo(bank.vault)
).data,
)
.amount.toNumber()}`;
`\n ${'vault'.padEnd(40)} ${vault}`;
console.log(`${res}`);
}