forked from solana-labs/governance-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlistingTools.ts
More file actions
755 lines (709 loc) · 21.6 KB
/
Copy pathlistingTools.ts
File metadata and controls
755 lines (709 loc) · 21.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
import {
Bank,
Group,
I80F48,
OPENBOOK_PROGRAM_ID,
RouteInfo,
toNative,
toUiDecimals,
toUiDecimalsForQuote,
} from '@blockworks-foundation/mango-v4'
import {
LISTING_PRESET,
LISTING_PRESETS,
LISTING_PRESETS_KEY,
getPresetWithAdjustedNetBorrows,
getPresetWithAdjustedDepositLimit,
getPythPresets,
getSwitchBoardPresets,
} from '@blockworks-foundation/mango-v4-settings/lib/helpers/listingTools'
import { AnchorProvider, BN, Program, Wallet } from '@coral-xyz/anchor'
import { MAINNET_USDC_MINT } from '@foresight-tmp/foresight-sdk/dist/consts'
import { Market } from '@project-serum/serum'
import { PythHttpClient, parsePriceData } from '@pythnetwork/client'
import {
AccountInfo,
Connection,
Keypair,
PublicKey,
Transaction,
VersionedTransaction,
} from '@solana/web3.js'
import SwitchboardProgram from '@switchboard-xyz/sbv2-lite'
import { notify } from '@utils/notifications'
import Big from 'big.js'
import { secondsToHours } from 'date-fns'
export const REDUCE_ONLY_OPTIONS = [
{ value: 0, name: 'Disabled' },
{ value: 1, name: 'No borrows and no deposits' },
{ value: 2, name: 'No borrows' },
]
const MAINNET_PYTH_PROGRAM = new PublicKey(
'FsJ3A3u2vn5cTVofAjvy6y5kwABJAqYWpe4975bi2epH'
)
export type FlatListingArgs = {
name: string
tokenIndex: number
'oracleConfig.confFilter': number
'oracleConfig.maxStalenessSlots': number | null
'interestRateParams.util0': number
'interestRateParams.rate0': number
'interestRateParams.util1': number
'interestRateParams.rate1': number
'interestRateParams.maxRate': number
'interestRateParams.adjustmentFactor': number
loanFeeRate: number
loanOriginationFeeRate: number
maintAssetWeight: number
initAssetWeight: number
maintLiabWeight: number
initLiabWeight: number
liquidationFee: number
platformLiquidationFee: number
minVaultToDepositsRatio: number
netBorrowLimitPerWindowQuote: number
netBorrowLimitWindowSizeTs: number
borrowWeightScaleStartQuote: number
depositWeightScaleStartQuote: number
stablePriceDelayGrowthLimit: number
stablePriceDelayIntervalSeconds: number
stablePriceGrowthLimit: number
tokenConditionalSwapMakerFeeRate: number
tokenConditionalSwapTakerFeeRate: number
flashLoanSwapFeeRate: number
reduceOnly: number
groupInsuranceFund: boolean
oracle: PublicKey
depositLimit: number
interestTargetUtilization: number
interestCurveScaling: number
setFallbackOracle: boolean
maintWeightShiftAbort: boolean
zeroUtilRate: number
disableAssetLiquidation: boolean
collateralFeePerDay: number
}
export type FlatEditArgs = {
nameOpt: string
tokenIndex: number
'oracleConfigOpt.confFilter': number
'oracleConfigOpt.maxStalenessSlots': number
'interestRateParamsOpt.util0': number
'interestRateParamsOpt.rate0': number
'interestRateParamsOpt.util1': number
'interestRateParamsOpt.rate1': number
'interestRateParamsOpt.maxRate': number
'interestRateParamsOpt.adjustmentFactor': number
loanFeeRateOpt: number
loanOriginationFeeRateOpt: number
maintAssetWeightOpt: number
initAssetWeightOpt: number
maintLiabWeightOpt: number
initLiabWeightOpt: number
liquidationFeeOpt: number
platformLiquidationFeeOpt: number
minVaultToDepositsRatioOpt: number
netBorrowLimitPerWindowQuoteOpt: number
netBorrowLimitWindowSizeTsOpt: number
borrowWeightScaleStartQuoteOpt: number
depositWeightScaleStartQuoteOpt: number
stablePriceDelayGrowthLimitOpt: number
stablePriceDelayIntervalSecondsOpt: number
stablePriceGrowthLimitOpt: number
tokenConditionalSwapMakerFeeRateOpt: number
tokenConditionalSwapTakerFeeRateOpt: number
flashLoanSwapFeeRateOpt: number
reduceOnlyOpt: number
groupInsuranceFundOpt: boolean
oracleOpt: PublicKey
interestCurveScalingOpt: number
interestTargetUtilizationOpt: number
maintWeightShiftStartOpt: BN
maintWeightShiftEndOpt: BN
maintWeightShiftAssetTargetOpt: number
maintWeightShiftLiabTargetOpt: number
maintWeightShiftAbort: boolean
setFallbackOracle: boolean
depositLimitOpt: number
zeroUtilRateOpt: number
disableAssetLiquidationOpt: boolean
collateralFeePerDayOpt: number
forceWithdrawOpt: boolean
forceCloseOpt: boolean
}
export type ListingArgsFormatted = {
tokenIndex: number
tokenName: string
oracleConfidenceFilter: string
oracleMaxStalenessSlots: number | null
interestRateUtilizationPoint1: string
interestRateUtilizationPoint0: string
interestRatePoint0: string
interestRatePoint1: string
adjustmentFactor: string
maxRate: string
loanFeeRate: string
loanOriginationFeeRate: string
maintAssetWeight: string
initAssetWeight: string
maintLiabWeight: string
initLiabWeight: string
liquidationFee: string
platformLiquidationFee: string
minVaultToDepositsRatio: string
netBorrowLimitPerWindowQuote: number
netBorrowLimitWindowSizeTs: number
borrowWeightScaleStartQuote: number
depositWeightScaleStartQuote: number
stablePriceDelayGrowthLimit: string
stablePriceDelayIntervalSeconds: number
stablePriceGrowthLimit: string
tokenConditionalSwapMakerFeeRate: number
tokenConditionalSwapTakerFeeRate: number
flashLoanSwapFeeRate: string
reduceOnly: string
oracle: string
depositLimit: string
interestTargetUtilization: number
interestCurveScaling: number
groupInsuranceFund: boolean
zeroUtilRate: number
disableAssetLiquidation: boolean
collateralFeePerDay: string
}
export type EditTokenArgsFormatted = ListingArgsFormatted & {
maintWeightShiftStart: number
maintWeightShiftEnd: number
maintWeightShiftAssetTarget: number
maintWeightShiftLiabTarget: number
maintWeightShiftAbort: boolean
setFallbackOracle: boolean
forceWithdraw: boolean
forceClose: boolean
}
const transformPresetToProposed = (listingPreset: LISTING_PRESET) => {
const proposedPreset: FormattedListingPreset = {
...listingPreset,
'oracleConfig.maxStalenessSlots':
listingPreset.maxStalenessSlots === -1
? null
: listingPreset.maxStalenessSlots!,
'oracleConfig.confFilter': listingPreset.oracleConfFilter,
'interestRateParams.adjustmentFactor': listingPreset.adjustmentFactor,
'interestRateParams.util0': listingPreset.util0,
'interestRateParams.rate0': listingPreset.rate0,
'interestRateParams.util1': listingPreset.util1,
'interestRateParams.rate1': listingPreset.rate1,
'interestRateParams.maxRate': listingPreset.maxRate,
groupInsuranceFund: listingPreset.groupInsuranceFund,
maintWeightShiftAbort: false,
setFallbackOracle: false,
}
return proposedPreset
}
type FormattedListingPreset = Omit<
FlatListingArgs,
'name' | 'tokenIndex' | 'oracle'
>
type ProposedListingPresets = {
[key in LISTING_PRESETS_KEY]: FormattedListingPreset
}
export const getFormattedListingPresets = (
isPythOracle: boolean,
uiDeposits?: number,
decimals?: number,
tokenPrice?: number
) => {
const PRESETS = !isPythOracle
? getSwitchBoardPresets(LISTING_PRESETS)
: getPythPresets(LISTING_PRESETS)
const PROPOSED_LISTING_PRESETS: ProposedListingPresets = Object.keys(
PRESETS
).reduce((accumulator, key) => {
let adjustedPreset = PRESETS[key]
if (uiDeposits && tokenPrice) {
adjustedPreset = getPresetWithAdjustedNetBorrows(
PRESETS[key],
uiDeposits,
tokenPrice,
toUiDecimals(PRESETS[key].netBorrowLimitPerWindowQuote, 6)
)
}
if (decimals && tokenPrice) {
adjustedPreset = getPresetWithAdjustedDepositLimit(
adjustedPreset,
tokenPrice,
decimals
)
}
accumulator[key] = transformPresetToProposed(adjustedPreset)
return accumulator
}, {} as ProposedListingPresets)
return PROPOSED_LISTING_PRESETS
}
const fetchJupiterRoutes = async (
inputMint = 'So11111111111111111111111111111111111111112',
outputMint = 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
amount = 0,
swapMode = 'ExactIn',
slippage = 50,
feeBps = 0
) => {
{
try {
const paramsString = new URLSearchParams({
inputMint: inputMint.toString(),
outputMint: outputMint.toString(),
amount: amount.toString(),
slippageBps: Math.ceil(slippage * 100).toString(),
feeBps: feeBps.toString(),
swapMode,
}).toString()
const jupiterSwapBaseUrl =
process.env.NEXT_PUBLIC_JUPTER_SWAP_API_ENDPOINT ||
'https://public.jupiterapi.com'
const response = await fetch(
`${jupiterSwapBaseUrl}/quote?${paramsString}`
)
const res = await response.json()
return {
bestRoute: (res ? res : null) as RouteInfo | null,
}
} catch (e) {
console.log(e)
return {
bestRoute: null,
}
}
}
}
export const getSuggestedCoinPresetInfo = async (
outputMint: string,
hasPythOracle: boolean
) => {
try {
const PRESETS = !hasPythOracle
? getSwitchBoardPresets(LISTING_PRESETS)
: getPythPresets(LISTING_PRESETS)
const swaps = await Promise.all([
fetchJupiterRoutes(
MAINNET_USDC_MINT.toBase58(),
outputMint,
toNative(250000, 6).toNumber()
),
fetchJupiterRoutes(
MAINNET_USDC_MINT.toBase58(),
outputMint,
toNative(100000, 6).toNumber()
),
fetchJupiterRoutes(
MAINNET_USDC_MINT.toBase58(),
outputMint,
toNative(20000, 6).toNumber()
),
fetchJupiterRoutes(
MAINNET_USDC_MINT.toBase58(),
outputMint,
toNative(10000, 6).toNumber()
),
fetchJupiterRoutes(
MAINNET_USDC_MINT.toBase58(),
outputMint,
toNative(5000, 6).toNumber()
),
fetchJupiterRoutes(
MAINNET_USDC_MINT.toBase58(),
outputMint,
toNative(1000, 6).toNumber()
),
fetchJupiterRoutes(
MAINNET_USDC_MINT.toBase58(),
outputMint,
toNative(250000, 6).toNumber(),
'ExactOut'
),
fetchJupiterRoutes(
MAINNET_USDC_MINT.toBase58(),
outputMint,
toNative(100000, 6).toNumber(),
'ExactOut'
),
fetchJupiterRoutes(
MAINNET_USDC_MINT.toBase58(),
outputMint,
toNative(20000, 6).toNumber(),
'ExactOut'
),
fetchJupiterRoutes(
MAINNET_USDC_MINT.toBase58(),
outputMint,
toNative(20000, 6).toNumber(),
'ExactOut'
),
fetchJupiterRoutes(
MAINNET_USDC_MINT.toBase58(),
outputMint,
toNative(5000, 6).toNumber(),
'ExactOut'
),
fetchJupiterRoutes(
MAINNET_USDC_MINT.toBase58(),
outputMint,
toNative(1000, 6).toNumber(),
'ExactOut'
),
])
const bestRoutesSwaps = swaps
.filter((x) => x.bestRoute)
.map((x) => x.bestRoute!)
const averageSwaps = bestRoutesSwaps.reduce(
(acc: { amount: string; priceImpactPct: number }[], val) => {
if (val.swapMode === 'ExactIn') {
const exactOutRoute = bestRoutesSwaps.find(
(x) => x.outAmount === val.inAmount && x.swapMode === 'ExactOut'
)
acc.push({
amount: val.inAmount.toString(),
priceImpactPct: exactOutRoute?.priceImpactPct
? (Number(val.priceImpactPct) +
Number(exactOutRoute.priceImpactPct)) /
2
: Number(val.priceImpactPct),
})
}
return acc
},
[]
)
const indexForTargetAmount = averageSwaps.findIndex(
(x) => x?.priceImpactPct && x?.priceImpactPct * 100 < 1
)
const targetAmount =
indexForTargetAmount > -1
? toUiDecimals(new BN(averageSwaps[indexForTargetAmount].amount), 6)
: 0
const preset: LISTING_PRESET =
Object.values(PRESETS).find(
(x) => x.preset_target_amount === targetAmount
) || PRESETS.UNTRUSTED
return {
presetKey: preset.preset_key,
priceImpact: (indexForTargetAmount > -1
? averageSwaps[indexForTargetAmount]!.priceImpactPct
: 100
).toFixed(2),
}
} catch (e) {
console.log(e)
return {
presetKey: 'UNTRUSTED',
priceImpact: '100',
}
}
}
export const compareObjectsAndGetDifferentKeys = <T extends object>(
object1: T,
object2: T
): (keyof T)[] => {
const diffKeys: string[] = []
Object.keys(object1).forEach((key) => {
if (object1[key] !== object2[key]) {
diffKeys.push(key)
}
})
return diffKeys as (keyof T)[]
}
const isSwitchboardOracle = async (
connection: Connection,
feedPk: PublicKey
) => {
const SWITCHBOARD_PROGRAM_ID = 'SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f'
const options = AnchorProvider.defaultOptions()
const provider = new AnchorProvider(
connection,
new EmptyWallet(Keypair.generate()),
options
)
const idl = await Program.fetchIdl(
new PublicKey(SWITCHBOARD_PROGRAM_ID),
provider
)
const switchboardProgram = new Program(
idl!,
new PublicKey(SWITCHBOARD_PROGRAM_ID),
provider
)
const feeds = await switchboardProgram.account.aggregatorAccountData.all()
const feed = feeds.find((x) => x.publicKey.equals(feedPk))
return feed
? `https://app.switchboard.xyz/solana/mainnet-beta/feed/${feedPk.toBase58()}`
: ''
}
export const isPythOracle = async (
connection: Connection,
feedPk: PublicKey
) => {
const pythClient = new PythHttpClient(connection, MAINNET_PYTH_PROGRAM)
const pythAccounts = await pythClient.getData()
const feed = pythAccounts.products.find(
(x) => x.price_account === feedPk.toBase58()
)
if (feed) {
return `https://pyth.network/price-feeds/${feed.asset_type.toLowerCase()}-${feed.base.toLowerCase()}-${feed.quote_currency.toLowerCase()}?cluster=solana-mainnet-beta`
}
return ''
}
export const getOracle = async (connection: Connection, feedPk: PublicKey) => {
const switchboardUrl = await isSwitchboardOracle(connection, feedPk)
if (switchboardUrl) {
return {
type: 'Switchboard',
url: switchboardUrl,
}
}
const pythUrl = await isPythOracle(connection, feedPk)
if (pythUrl) {
return {
type: 'Pyth',
url: pythUrl,
}
}
return {
type: 'Unknown',
url: '',
}
}
export default class EmptyWallet implements Wallet {
constructor(readonly payer: Keypair) {}
async signTransaction<T extends Transaction | VersionedTransaction>(
tx: T
): Promise<T> {
if (tx instanceof Transaction) {
tx.partialSign(this.payer)
}
return tx
}
async signAllTransactions<T extends Transaction | VersionedTransaction>(
txs: T[]
): Promise<T[]> {
return txs.map((t) => {
if (t instanceof Transaction) {
t.partialSign(this.payer)
}
return t
})
}
get publicKey(): PublicKey {
return this.payer.publicKey
}
}
export const getBestMarket = async ({
baseMint,
quoteMint,
cluster,
connection,
}: {
baseMint: string
quoteMint: string
cluster: 'devnet' | 'mainnet-beta'
connection: Connection
}) => {
try {
const dexProgramPk = OPENBOOK_PROGRAM_ID[cluster]
const markets = await Market.findAccountsByMints(
connection,
new PublicKey(baseMint),
new PublicKey(quoteMint),
dexProgramPk
)
if (!markets.length) {
return undefined
}
const marketsDataJsons = await Promise.all([
...markets.map((x) =>
fetch(`/openSerumApi/market/${x.publicKey.toBase58()}`)
),
])
const marketsData = await Promise.all([
...marketsDataJsons.map((x) => x.json()),
])
let error = ''
let sortedMarkets = marketsData.sort((a, b) => b.volume24h - a.volume24h)
let firstBestMarket = sortedMarkets[0]
if (firstBestMarket.volume24h === 0) {
error = 'Openbook market had 0 volume in last 24h check it carefully'
}
sortedMarkets = sortedMarkets.sort(
(a, b) => b.quoteDepositsTotal - a.quoteDepositsTotal
)
firstBestMarket = sortedMarkets[0]
return sortedMarkets.length
? { pubKey: new PublicKey(firstBestMarket.id), error: error }
: undefined
} catch (e) {
notify({
message: 'Openbook market not found',
type: 'error',
})
}
}
export const decodePriceFromOracleAi = async (
ai: AccountInfo<Buffer>,
connection: Connection,
type: string
): Promise<{
uiPrice: number
lastUpdatedSlot: number
deviation: string
}> => {
let uiPrice, lastUpdatedSlot, deviation
try {
if (type === 'Pyth') {
const priceData = parsePriceData(ai.data)
uiPrice = priceData.previousPrice
lastUpdatedSlot = parseInt(priceData.lastSlot.toString())
deviation =
priceData.previousConfidence !== undefined
? ((priceData.previousConfidence / uiPrice) * 100).toFixed(2)
: undefined
} else if (type === 'Switchboard') {
const program = await SwitchboardProgram.loadMainnet(connection)
uiPrice = program.decodeLatestAggregatorValue(ai)!.toNumber()
lastUpdatedSlot = program
.decodeAggregator(ai)
.latestConfirmedRound!.roundOpenSlot!.toNumber()
deviation = (
(switchboardDecimalToBig(
program.decodeAggregator(ai).latestConfirmedRound.stdDeviation
).toNumber() /
uiPrice) *
100
).toFixed(2)
}
return { uiPrice, lastUpdatedSlot, deviation }
} catch (e) {
return { uiPrice, lastUpdatedSlot, deviation }
}
}
export function switchboardDecimalToBig(sbDecimal: {
mantissa: BN
scale: number
}): Big {
const mantissa = new Big(sbDecimal.mantissa.toString())
const scale = sbDecimal.scale
const oldDp = Big.DP
Big.DP = 20
const result: Big = mantissa.div(new Big(10).pow(scale))
Big.DP = oldDp
return result
}
export const getFormattedBankValues = (group: Group, bank: Bank) => {
return {
...bank,
publicKey: bank.publicKey.toBase58(),
vault: bank.vault.toBase58(),
oracle: bank.oracle.toBase58(),
fallbackOracle: bank.fallbackOracle.toBase58(),
stablePrice: group.toUiPrice(
I80F48.fromNumber(bank.stablePriceModel.stablePrice),
bank.mintDecimals
),
maxStalenessSlots: bank.oracleConfig.maxStalenessSlots.toNumber(),
lastStablePriceUpdated: new Date(
1000 * bank.stablePriceModel.lastUpdateTimestamp.toNumber()
).toUTCString(),
stablePriceGrowthLimitsDelay: (
100 * bank.stablePriceModel.delayGrowthLimit
).toFixed(2),
stablePriceGrowthLimitsStable: (
100 * bank.stablePriceModel.stableGrowthLimit
).toFixed(2),
loanFeeRate: (10000 * bank.loanFeeRate.toNumber()).toFixed(2),
loanOriginationFeeRate: (
10000 * bank.loanOriginationFeeRate.toNumber()
).toFixed(2),
collectedFeesNative: toUiDecimals(
bank.collectedFeesNative.toNumber(),
bank.mintDecimals
).toFixed(2),
collectedFeesNativePrice: (
toUiDecimals(bank.collectedFeesNative.toNumber(), bank.mintDecimals) *
bank.uiPrice
).toFixed(2),
dust: bank.dust.toNumber(),
deposits: toUiDecimals(
bank.indexedDeposits.mul(bank.depositIndex).toNumber(),
bank.mintDecimals
),
depositsPrice: (
toUiDecimals(
bank.indexedDeposits.mul(bank.depositIndex).toNumber(),
bank.mintDecimals
) * bank.uiPrice
).toFixed(2),
borrows: toUiDecimals(
bank.indexedBorrows.mul(bank.borrowIndex).toNumber(),
bank.mintDecimals
),
borrowsPrice: (
toUiDecimals(
bank.indexedBorrows.mul(bank.borrowIndex).toNumber(),
bank.mintDecimals
) * bank.uiPrice
).toFixed(2),
avgUtilization: bank.avgUtilization.toNumber() * 100,
maintAssetWeight: bank.maintAssetWeight.toFixed(2),
maintLiabWeight: bank.maintLiabWeight.toFixed(2),
initAssetWeight: bank.initAssetWeight.toFixed(2),
initLiabWeight: bank.initLiabWeight.toFixed(2),
scaledInitAssetWeight: bank.scaledInitAssetWeight(bank.price).toFixed(2),
scaledInitLiabWeight: bank.scaledInitLiabWeight(bank.price).toFixed(2),
depositWeightScaleStartQuote: toUiDecimalsForQuote(
bank.depositWeightScaleStartQuote
),
borrowWeightScaleStartQuote: toUiDecimalsForQuote(
bank.borrowWeightScaleStartQuote
),
rate0: (100 * bank.rate0.toNumber()).toFixed(2),
util0: (100 * bank.util0.toNumber()).toFixed(),
rate1: (100 * bank.rate1.toNumber()).toFixed(2),
util1: (100 * bank.util1.toNumber()).toFixed(),
maxRate: (100 * bank.maxRate.toNumber()).toFixed(2),
adjustmentFactor: (bank.adjustmentFactor.toNumber() * 100).toFixed(2),
depositRate: bank.getDepositRateUi(),
borrowRate: bank.getBorrowRateUi(),
lastIndexUpdate: new Date(
1000 * bank.indexLastUpdated.toNumber()
).toUTCString(),
lastRatesUpdate: new Date(
1000 * bank.bankRateLastUpdated.toNumber()
).toUTCString(),
oracleConfFilter:
bank.oracleConfig.confFilter.toNumber() === Number.MAX_SAFE_INTEGER
? ''
: (100 * bank.oracleConfig.confFilter.toNumber()).toFixed(2),
minVaultToDepositsRatio: bank.minVaultToDepositsRatio * 100,
netBorrowsInWindow: toUiDecimalsForQuote(
I80F48.fromI64(bank.netBorrowsInWindow).mul(bank.price)
).toFixed(2),
netBorrowLimitPerWindowQuote: toUiDecimals(
bank.netBorrowLimitPerWindowQuote,
6
),
liquidationFee: (bank.liquidationFee.toNumber() * 100).toFixed(2),
platformLiquidationFee: (
bank.platformLiquidationFee.toNumber() * 100
).toFixed(2),
netBorrowLimitWindowSizeTs: secondsToHours(
bank.netBorrowLimitWindowSizeTs.toNumber()
),
depositLimit: bank.depositLimit.toString(),
interestTargetUtilization: bank.interestTargetUtilization,
interestCurveScaling: bank.interestCurveScaling,
reduceOnly: REDUCE_ONLY_OPTIONS[bank.reduceOnly].name,
maintWeightShiftStart: bank.maintWeightShiftStart.toNumber(),
maintWeightShiftEnd: bank.maintWeightShiftEnd.toNumber(),
maintWeightShiftAssetTarget: bank.maintWeightShiftAssetTarget.toNumber(),
maintWeightShiftLiabTarget: bank.maintWeightShiftLiabTarget.toNumber(),
}
}