added better printing of margin account;

This commit is contained in:
dd 2021-03-26 08:15:47 -04:00
parent c96c11b211
commit 8d846fe974
3 changed files with 23 additions and 10 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@blockworks-foundation/mango-client",
"version": "0.1.9",
"version": "0.1.10",
"description": "Library for interacting with Mango Markets' solana smart contracts.",
"repository": "blockworks-foundation/mango-client-ts",
"author": {

View File

@ -213,6 +213,7 @@ export class MarginAccount {
): string {
const lines = [
`MarginAccount: ${this.publicKey.toBase58()}`,
`Owner: ${this.owner.toBase58()}`,
`${"Token".padEnd(5)} ${"Assets".padEnd(10)} ${"Deposits".padEnd(10)} ${"Borrows".padEnd(10)}`,
]
@ -321,7 +322,7 @@ export class MarginAccount {
return assetsVal
}
getLiabsVal(mangoGroup: MangoGroup, prices: number[]) {
getLiabsVal(mangoGroup: MangoGroup, prices: number[]): number {
let liabsVal = 0
for (let i = 0; i < NUM_TOKENS; i++) {
liabsVal += this.getUiBorrow(mangoGroup, i) * prices[i]

View File

@ -1,6 +1,5 @@
import { MangoClient, MangoGroup } from './client';
import IDS from './ids.json';
import { Account, Connection, PublicKey } from '@solana/web3.js';
export { MangoClient, MangoGroup, MarginAccount, tokenToDecimals } from './client';
export { MangoIndexLayout, MarginAccountLayout, MangoGroupLayout } from './layout';
@ -9,12 +8,7 @@ export * from './utils'
export { IDS }
import { homedir } from 'os'
import * as fs from 'fs';
import { Aggregator } from './schema';
import { sleep } from './utils';
//
// async function tests() {
// const cluster = "mainnet-beta";
// const client = new MangoClient();
@ -52,7 +46,25 @@ import { sleep } from './utils';
//
// async function getMarginAccountDetails() {
// const mangoGroup = await client.getMangoGroup(connection, mangoGroupPk);
// console.log(mangoGroup.indexes[2].deposit, mangoGroup.indexes[2].borrow)
// const marginAccountPk = new PublicKey("Et4ieruYqyBAzfTpGqbFgYpddFXdFaGDtLDqFqs665Ui")
// const marginAccount = await client.getMarginAccount(connection, marginAccountPk, mangoGroup.dexProgramId)
// const prices = await mangoGroup.getPrices(connection)
//
// console.log(marginAccount.toPrettyString(mangoGroup, prices))
//
// for (let i = 0; i < NUM_TOKENS; i++) {
// console.log(i, marginAccount.getUiDeposit(mangoGroup, i), marginAccount.getUiBorrow(mangoGroup, i))
// }
// for (let i = 0; i < NUM_MARKETS; i++) {
// let openOrdersAccount = marginAccount.openOrdersAccounts[i]
// if (openOrdersAccount === undefined) {
// continue
// }
//
// console.log(i, nativeToUi(openOrdersAccount.quoteTokenTotal.toNumber(), mangoGroup.mintDecimals[NUM_MARKETS]),
// nativeToUi(openOrdersAccount.baseTokenTotal.toNumber(), mangoGroup.mintDecimals[i]))
// }
//
// }
// await getMarginAccountDetails()
// // await testSolink()