Add new token decimals, get token symbols from serum
This commit is contained in:
parent
0f47d83101
commit
3e1130c0c4
|
@ -35,7 +35,14 @@ import {
|
||||||
uiToNative,
|
uiToNative,
|
||||||
zeroKey,
|
zeroKey,
|
||||||
} from './utils';
|
} from './utils';
|
||||||
import { getFeeRates, getFeeTier, Market, OpenOrders, Orderbook } from '@project-serum/serum';
|
import {
|
||||||
|
getFeeRates,
|
||||||
|
getFeeTier,
|
||||||
|
Market,
|
||||||
|
OpenOrders,
|
||||||
|
Orderbook,
|
||||||
|
TOKEN_MINTS
|
||||||
|
} from '@project-serum/serum';
|
||||||
import { SRM_DECIMALS } from '@project-serum/serum/lib/token-instructions';
|
import { SRM_DECIMALS } from '@project-serum/serum/lib/token-instructions';
|
||||||
import { Order } from '@project-serum/serum/lib/market';
|
import { Order } from '@project-serum/serum/lib/market';
|
||||||
import Wallet from '@project-serum/sol-wallet-adapter';
|
import Wallet from '@project-serum/sol-wallet-adapter';
|
||||||
|
@ -52,12 +59,13 @@ import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
|
||||||
export const tokenToDecimals = {
|
export const tokenToDecimals = {
|
||||||
"BTC": 4,
|
"BTC": 4,
|
||||||
"ETH": 3,
|
"ETH": 3,
|
||||||
|
"SOL": 2,
|
||||||
|
"SRM": 2,
|
||||||
"USDT": 2,
|
"USDT": 2,
|
||||||
"USDC": 2
|
"USDC": 2,
|
||||||
|
"WUSDT": 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export class MangoGroup {
|
export class MangoGroup {
|
||||||
publicKey: PublicKey;
|
publicKey: PublicKey;
|
||||||
|
|
||||||
|
@ -158,6 +166,9 @@ export class MangoGroup {
|
||||||
getUiTotalBorrow(tokenIndex: number): number {
|
getUiTotalBorrow(tokenIndex: number): number {
|
||||||
return nativeToUi(this.totalBorrows[tokenIndex] * this.indexes[tokenIndex].borrow, this.mintDecimals[tokenIndex])
|
return nativeToUi(this.totalBorrows[tokenIndex] * this.indexes[tokenIndex].borrow, this.mintDecimals[tokenIndex])
|
||||||
}
|
}
|
||||||
|
getTokenSymbol(tokenIndex: number): string {
|
||||||
|
return TOKEN_MINTS.find((m) => m.address.toString() === this.tokens[tokenIndex].toString())?.name || '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class MarginAccount {
|
export class MarginAccount {
|
||||||
|
@ -223,16 +234,14 @@ export class MarginAccount {
|
||||||
`${"Token".padEnd(5)} ${"Assets".padEnd(10)} ${"Deposits".padEnd(10)} ${"Borrows".padEnd(10)}`,
|
`${"Token".padEnd(5)} ${"Assets".padEnd(10)} ${"Deposits".padEnd(10)} ${"Borrows".padEnd(10)}`,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
const tokenNames = ["BTC", "ETH", "USDT"] // TODO pull this from somewhere
|
|
||||||
|
|
||||||
for (let i = 0; i < mangoGroup.tokens.length; i++) {
|
for (let i = 0; i < mangoGroup.tokens.length; i++) {
|
||||||
const decimals = tokenToDecimals[tokenNames[i]]
|
const tokenSymbol = mangoGroup.getTokenSymbol(i)
|
||||||
|
const decimals = tokenToDecimals[tokenSymbol]
|
||||||
const assetStr = this.getAssets(mangoGroup)[i].toFixed(decimals).toString().padEnd(10)
|
const assetStr = this.getAssets(mangoGroup)[i].toFixed(decimals).toString().padEnd(10)
|
||||||
const depositStr = this.getUiDeposit(mangoGroup, i).toFixed(decimals).toString().padEnd(10)
|
const depositStr = this.getUiDeposit(mangoGroup, i).toFixed(decimals).toString().padEnd(10)
|
||||||
const borrowStr = this.getUiBorrow(mangoGroup, i).toFixed(decimals).toString().padEnd(10)
|
const borrowStr = this.getUiBorrow(mangoGroup, i).toFixed(decimals).toString().padEnd(10)
|
||||||
lines.push(
|
lines.push(
|
||||||
`${tokenNames[i].padEnd(5)} ${assetStr} ${depositStr} ${borrowStr}`
|
`${tokenSymbol.padEnd(5)} ${assetStr} ${depositStr} ${borrowStr}`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue