From 03dbac82f9821f581f93a877772a97fdedf67dc6 Mon Sep 17 00:00:00 2001 From: microwavedcola1 Date: Mon, 15 Aug 2022 19:13:18 +0200 Subject: [PATCH] error for debugging banks Signed-off-by: microwavedcola1 --- ts/client/src/debug-scripts/mb-debug-banks.ts | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/ts/client/src/debug-scripts/mb-debug-banks.ts b/ts/client/src/debug-scripts/mb-debug-banks.ts index ddaa6b7f5..275ae337a 100644 --- a/ts/client/src/debug-scripts/mb-debug-banks.ts +++ b/ts/client/src/debug-scripts/mb-debug-banks.ts @@ -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}`); }