@scallop-io/sui-scallop-sdk 0.42.7 → 0.42.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -64,6 +64,7 @@ export declare class ScallopUtils {
64
64
  */
65
65
  parseCoinNameFromType<T extends SupportAssetCoins>(coinType: string): T extends SupportAssetCoins ? T : SupportAssetCoins;
66
66
  parseCoinNameFromType<T extends SupportMarketCoins>(coinType: string): T extends SupportMarketCoins ? T : SupportMarketCoins;
67
+ parseCoinNameFromType<T extends SupportCoins>(coinType: string): T extends SupportCoins ? T : SupportCoins;
67
68
  /**
68
69
  * Convert marke coin name to coin name.
69
70
  *
@@ -14,3 +14,11 @@ export type StakeMarketCoins = {
14
14
  export type RewardCoins = {
15
15
  [key in SupportStakeMarketCoins]: SupportRewardCoins;
16
16
  };
17
+ export type AssetCoinIds = {
18
+ [key in SupportAssetCoins]: string;
19
+ };
20
+ type PickFromUnion<T, K extends string> = K extends T ? K : never;
21
+ export type WormholeCoinIds = {
22
+ [key in PickFromUnion<SupportAssetCoins, 'eth' | 'btc' | 'usdc' | 'usdt' | 'apt' | 'sol'>]: string;
23
+ };
24
+ export {};
@@ -115,7 +115,7 @@ export type MarketPool = {
115
115
  coinWrappedType: CoinWrappedType;
116
116
  coinDecimal: number;
117
117
  coinPrice: number;
118
- } & Required<Pick<ParsedMarketPoolData, 'reserveFactor' | 'borrowWeight' | 'marketCoinSupplyAmount' | 'minBorrowAmount'>> & CalculatedMarketPoolData;
118
+ } & Required<Pick<ParsedMarketPoolData, 'highKink' | 'midKink' | 'reserveFactor' | 'borrowWeight' | 'marketCoinSupplyAmount' | 'minBorrowAmount'>> & CalculatedMarketPoolData;
119
119
  export type MarketCollateral = {
120
120
  coinName: SupportCollateralCoins;
121
121
  symbol: string;
@@ -17,11 +17,21 @@ export type Lending = Required<Pick<MarketPool, 'coinName' | 'symbol' | 'coinTyp
17
17
  stakedAmount: number;
18
18
  stakedCoin: number;
19
19
  stakedValue: number;
20
+ unstakedMarketAmount: number;
21
+ unstakedMarketCoin: number;
22
+ unstakedAmount: number;
23
+ unstakedCoin: number;
24
+ unstakedValue: number;
20
25
  availableSupplyAmount: number;
26
+ availableSupplyCoin: number;
21
27
  availableWithdrawAmount: number;
28
+ availableWithdrawCoin: number;
22
29
  availableStakeAmount: number;
30
+ availableStakeCoin: number;
23
31
  availableUnstakeAmount: number;
32
+ availableUnstakeCoin: number;
24
33
  availableClaimAmount: number;
34
+ availableClaimCoin: number;
25
35
  };
26
36
  export type ObligationAccount = {
27
37
  obligationId: string;
@@ -36,34 +46,40 @@ export type ObligationAccount = {
36
46
  totalRiskLevel: number;
37
47
  totalDepositedPools: number;
38
48
  totalBorrowedPools: number;
39
- collaterals: OptionalKeys<Record<SupportCollateralCoins, {
40
- coinName: SupportCollateralCoins;
41
- coinType: string;
42
- symbol: string;
43
- depositedAmount: number;
44
- depositedCoin: number;
45
- depositedValue: number;
46
- borrowCapacityValue: number;
47
- requiredCollateralValue: number;
48
- availableDepositAmount: number;
49
- availableDepositCoin: number;
50
- availableWithdrawAmount: number;
51
- availableWithdrawCoin: number;
52
- }>>;
53
- debts: OptionalKeys<Record<SupportPoolCoins, {
54
- coinName: SupportPoolCoins;
55
- coinType: string;
56
- symbol: string;
57
- borrowedAmount: number;
58
- borrowedCoin: number;
59
- borrowedValue: number;
60
- borrowedValueWithWeight: number;
61
- borrowIndex: number;
62
- availableBorrowAmount: number;
63
- availableBorrowCoin: number;
64
- availableRepayAmount: number;
65
- availableRepayCoin: number;
66
- }>>;
49
+ collaterals: OptionalKeys<Record<SupportCollateralCoins, ObligationCollateral>>;
50
+ debts: OptionalKeys<Record<SupportPoolCoins, ObligationDebt>>;
51
+ };
52
+ export type ObligationCollateral = {
53
+ coinName: SupportCollateralCoins;
54
+ coinType: string;
55
+ symbol: string;
56
+ coinDecimal: number;
57
+ coinPrice: number;
58
+ depositedAmount: number;
59
+ depositedCoin: number;
60
+ depositedValue: number;
61
+ borrowCapacityValue: number;
62
+ requiredCollateralValue: number;
63
+ availableDepositAmount: number;
64
+ availableDepositCoin: number;
65
+ availableWithdrawAmount: number;
66
+ availableWithdrawCoin: number;
67
+ };
68
+ export type ObligationDebt = {
69
+ coinName: SupportPoolCoins;
70
+ coinType: string;
71
+ symbol: string;
72
+ coinDecimal: number;
73
+ coinPrice: number;
74
+ borrowedAmount: number;
75
+ borrowedCoin: number;
76
+ borrowedValue: number;
77
+ borrowedValueWithWeight: number;
78
+ borrowIndex: number;
79
+ availableBorrowAmount: number;
80
+ availableBorrowCoin: number;
81
+ availableRepayAmount: number;
82
+ availableRepayCoin: number;
67
83
  };
68
84
  export type TotalValueLocked = {
69
85
  supplyValue: number;
@@ -72,7 +72,7 @@ export type ParsedRewardPoolData = {
72
72
  spoolId: string;
73
73
  };
74
74
  export type CalculatedRewardPoolData = {
75
- stakeApr: number;
75
+ rewardApr: number;
76
76
  totalRewardAmount: number;
77
77
  totalRewardCoin: number;
78
78
  totalRewardValue: number;
@@ -1,3 +1,4 @@
1
+ import BigNumber from 'bignumber.js';
1
2
  import type { ScallopUtils } from '../models';
2
3
  import type { OriginMarketPoolData, ParsedMarketPoolData, CalculatedMarketPoolData, OriginMarketCollateralData, ParsedMarketCollateralData, CalculatedMarketCollateralData, OriginStakePoolData, ParsedStakePoolData, CalculatedStakePoolData, OriginRewardPoolData, ParsedRewardPoolData, CalculatedRewardPoolData } from '../types';
3
4
  /**
@@ -32,3 +33,5 @@ export declare const calculateStakePoolData: (parsedStakePoolData: ParsedStakePo
32
33
  */
33
34
  export declare const parseOriginRewardPoolData: (originRewardPoolData: OriginRewardPoolData) => ParsedRewardPoolData;
34
35
  export declare const calculateRewardPoolData: (parsedStakePoolData: ParsedStakePoolData, parsedRewardPoolData: ParsedRewardPoolData, calculatedStakePoolData: CalculatedStakePoolData, rewardCoinPrice: number, rewardCoinDecimal: number) => CalculatedRewardPoolData;
36
+ export declare const minBigNumber: (...args: BigNumber.Value[]) => BigNumber;
37
+ export declare const maxBigNumber: (...args: BigNumber.Value[]) => BigNumber;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scallop-io/sui-scallop-sdk",
3
- "version": "0.42.7",
3
+ "version": "0.42.8",
4
4
  "description": "Typescript sdk for interacting with Scallop contract on SUI",
5
5
  "keywords": [
6
6
  "sui",
@@ -4,6 +4,8 @@ import type {
4
4
  MarketCoins,
5
5
  StakeMarketCoins,
6
6
  RewardCoins,
7
+ AssetCoinIds,
8
+ WormholeCoinIds,
7
9
  } from '../types';
8
10
 
9
11
  export const coinDecimals: SupportCoinDecimals = {
@@ -58,3 +60,23 @@ export const rewardCoins: RewardCoins = {
58
60
  susdc: 'sui',
59
61
  susdt: 'sui',
60
62
  };
63
+
64
+ export const coinIds: AssetCoinIds = {
65
+ sui: '0x0000000000000000000000000000000000000000000000000000000000000002',
66
+ eth: '0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5',
67
+ btc: '0x027792d9fed7f9844eb4839566001bb6f6cb4804f66aa2da6fe1ee242d896881',
68
+ usdc: '0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf',
69
+ usdt: '0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c',
70
+ apt: '0x3a5143bb1196e3bcdfab6203d1683ae29edd26294fc8bfeafe4aaa9d2704df37',
71
+ sol: '0xb7844e289a8410e50fb3ca48d69eb9cf29e27d223ef90353fe1bd8e27ff8f3f8',
72
+ cetus: '0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b',
73
+ };
74
+
75
+ export const wormholeCoinIds: WormholeCoinIds = {
76
+ eth: '0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5',
77
+ btc: '0x027792d9fed7f9844eb4839566001bb6f6cb4804f66aa2da6fe1ee242d896881',
78
+ usdc: '0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf',
79
+ usdt: '0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c',
80
+ apt: '0x3a5143bb1196e3bcdfab6203d1683ae29edd26294fc8bfeafe4aaa9d2704df37',
81
+ sol: '0xb7844e289a8410e50fb3ca48d69eb9cf29e27d223ef90353fe1bd8e27ff8f3f8',
82
+ };
@@ -10,6 +10,8 @@ import {
10
10
  SUPPORT_COLLATERALS,
11
11
  rewardCoins,
12
12
  coinDecimals,
13
+ wormholeCoinIds,
14
+ coinIds,
13
15
  } from '../constants';
14
16
  import { queryObligation } from '../queries';
15
17
  import { parseDataFromPythPriceFeed, isMarketCoin } from '../utils';
@@ -108,16 +110,22 @@ export class ScallopUtils {
108
110
  */
109
111
  public parseCoinType(coinName: SupportCoins) {
110
112
  coinName = isMarketCoin(coinName) ? this.parseCoinName(coinName) : coinName;
111
- const coinPackageId = this._address.get(`core.coins.${coinName}.id`);
113
+ const coinPackageId =
114
+ this._address.get(`core.coins.${coinName}.id`) ??
115
+ coinIds[coinName] ??
116
+ undefined;
117
+ if (!coinPackageId) {
118
+ throw Error(`Coin ${coinName} is not supported`);
119
+ }
112
120
  if (coinName === 'sui')
113
121
  return normalizeStructTag(`${coinPackageId}::sui::SUI`);
114
122
  const wormHoleCoinIds = [
115
- this._address.get('core.coins.usdc.id'),
116
- this._address.get('core.coins.usdt.id'),
117
- this._address.get('core.coins.eth.id'),
118
- this._address.get('core.coins.btc.id'),
119
- this._address.get('core.coins.sol.id'),
120
- this._address.get('core.coins.apt.id'),
123
+ this._address.get('core.coins.usdc.id') ?? wormholeCoinIds.usdc,
124
+ this._address.get('core.coins.usdt.id') ?? wormholeCoinIds.usdt,
125
+ this._address.get('core.coins.eth.id') ?? wormholeCoinIds.eth,
126
+ this._address.get('core.coins.btc.id') ?? wormholeCoinIds.btc,
127
+ this._address.get('core.coins.sol.id') ?? wormholeCoinIds.sol,
128
+ this._address.get('core.coins.apt.id') ?? wormholeCoinIds.apt,
121
129
  ];
122
130
  if (wormHoleCoinIds.includes(coinPackageId)) {
123
131
  return `${coinPackageId}::coin::COIN`;
@@ -154,6 +162,9 @@ export class ScallopUtils {
154
162
  public parseCoinNameFromType<T extends SupportMarketCoins>(
155
163
  coinType: string
156
164
  ): T extends SupportMarketCoins ? T : SupportMarketCoins;
165
+ public parseCoinNameFromType<T extends SupportCoins>(
166
+ coinType: string
167
+ ): T extends SupportCoins ? T : SupportCoins;
157
168
  public parseCoinNameFromType(coinType: string) {
158
169
  coinType = normalizeStructTag(coinType);
159
170
  const coinTypeRegex = new RegExp(`((0x[^:]+::[^:]+::[^<>]+))(?![^<>]*<)`);
@@ -162,12 +173,24 @@ export class ScallopUtils {
162
173
  coinType = coinTypeMatch?.[1] || coinType;
163
174
 
164
175
  const wormHoleCoinTypeMap: Record<string, SupportAssetCoins> = {
165
- [`${this._address.get('core.coins.usdc.id')}::coin::COIN`]: 'usdc',
166
- [`${this._address.get('core.coins.usdt.id')}::coin::COIN`]: 'usdt',
167
- [`${this._address.get('core.coins.eth.id')}::coin::COIN`]: 'eth',
168
- [`${this._address.get('core.coins.btc.id')}::coin::COIN`]: 'btc',
169
- [`${this._address.get('core.coins.sol.id')}::coin::COIN`]: 'sol',
170
- [`${this._address.get('core.coins.apt.id')}::coin::COIN`]: 'apt',
176
+ [`${
177
+ this._address.get('core.coins.usdc.id') ?? wormholeCoinIds.usdc
178
+ }::coin::COIN`]: 'usdc',
179
+ [`${
180
+ this._address.get('core.coins.usdt.id') ?? wormholeCoinIds.usdt
181
+ }::coin::COIN`]: 'usdt',
182
+ [`${
183
+ this._address.get('core.coins.eth.id') ?? wormholeCoinIds.eth
184
+ }::coin::COIN`]: 'eth',
185
+ [`${
186
+ this._address.get('core.coins.btc.id') ?? wormholeCoinIds.btc
187
+ }::coin::COIN`]: 'btc',
188
+ [`${
189
+ this._address.get('core.coins.sol.id') ?? wormholeCoinIds.sol
190
+ }::coin::COIN`]: 'sol',
191
+ [`${
192
+ this._address.get('core.coins.apt.id') ?? wormholeCoinIds.apt
193
+ }::coin::COIN`]: 'apt',
171
194
  };
172
195
 
173
196
  const assetCoinName =
@@ -98,6 +98,8 @@ export const queryMarket = async (query: ScallopQuery) => {
98
98
  coinWrappedType: query.utils.getCoinWrappedType(poolCoinName),
99
99
  coinDecimal: query.utils.getCoinDecimal(poolCoinName),
100
100
  coinPrice: coinPrice,
101
+ highKink: parsedMarketPoolData.highKink,
102
+ midKink: parsedMarketPoolData.midKink,
101
103
  reserveFactor: parsedMarketPoolData.reserveFactor,
102
104
  borrowWeight: parsedMarketPoolData.borrowWeight,
103
105
  marketCoinSupplyAmount: parsedMarketPoolData.marketCoinSupplyAmount,
@@ -352,6 +354,8 @@ export const getMarketPool = async (
352
354
  coinWrappedType: query.utils.getCoinWrappedType(poolCoinName),
353
355
  coinDecimal: query.utils.getCoinDecimal(poolCoinName),
354
356
  coinPrice: coinPrice ?? 0,
357
+ highKink: parsedMarketPoolData.highKink,
358
+ midKink: parsedMarketPoolData.midKink,
355
359
  reserveFactor: parsedMarketPoolData.reserveFactor,
356
360
  borrowWeight: parsedMarketPoolData.borrowWeight,
357
361
  marketCoinSupplyAmount: parsedMarketPoolData.marketCoinSupplyAmount,
@@ -1,5 +1,6 @@
1
1
  import BigNumber from 'bignumber.js';
2
2
  import { SUPPORT_POOLS, SUPPORT_SPOOLS } from '../constants';
3
+ import { minBigNumber } from 'src/utils';
3
4
  import type { ScallopQuery } from '../models';
4
5
  import type {
5
6
  Market,
@@ -133,7 +134,9 @@ export const getLending = async (
133
134
  let stakedCoin = BigNumber(0);
134
135
  let stakedValue = BigNumber(0);
135
136
  let availableUnstakeAmount = BigNumber(0);
137
+ let availableUnstakeCoin = BigNumber(0);
136
138
  let availableClaimAmount = BigNumber(0);
139
+ let availableClaimCoin = BigNumber(0);
137
140
 
138
141
  if (spool) {
139
142
  for (const stakeAccount of stakeAccounts) {
@@ -161,6 +164,7 @@ export const getLending = async (
161
164
  availableUnstakeAmount = availableUnstakeAmount.plus(
162
165
  accountStakedMarketCoinAmount
163
166
  );
167
+ availableUnstakeCoin = availableUnstakeAmount.shiftedBy(-1 * coinDecimal);
164
168
 
165
169
  const baseIndexRate = 1_000_000_000;
166
170
  const increasedPointRate = spool?.currentPointIndex
@@ -175,6 +179,7 @@ export const getLending = async (
175
179
  .multipliedBy(spool.exchangeRateNumerator)
176
180
  .dividedBy(spool.exchangeRateDenominator)
177
181
  );
182
+ availableClaimCoin = availableClaimAmount.shiftedBy(-1 * coinDecimal);
178
183
  }
179
184
  }
180
185
 
@@ -185,6 +190,20 @@ export const getLending = async (
185
190
  const suppliedCoin = suppliedAmount.shiftedBy(-1 * coinDecimal);
186
191
  const suppliedValue = suppliedCoin.multipliedBy(coinPrice ?? 0);
187
192
 
193
+ const unstakedMarketAmount = BigNumber(marketCoinAmount);
194
+ const unstakedMarketCoin = unstakedMarketAmount.shiftedBy(-1 * coinDecimal);
195
+
196
+ const availableSupplyAmount = BigNumber(coinAmount);
197
+ const availableSupplyCoin = availableSupplyAmount.shiftedBy(-1 * coinDecimal);
198
+ const availableWithdrawAmount = minBigNumber(
199
+ suppliedAmount,
200
+ marketPool?.supplyAmount ?? Infinity
201
+ ).plus(stakedAmount);
202
+ const availableWithdrawCoin = minBigNumber(
203
+ suppliedCoin,
204
+ marketPool?.supplyCoin ?? Infinity
205
+ ).plus(stakedCoin);
206
+
188
207
  const lending: Lending = {
189
208
  coinName: poolCoinName,
190
209
  symbol: query.utils.parseSymbol(poolCoinName),
@@ -194,7 +213,7 @@ export const getLending = async (
194
213
  coinPrice: coinPrice ?? 0,
195
214
  supplyApr: marketPool?.supplyApr ?? 0,
196
215
  supplyApy: marketPool?.supplyApy ?? 0,
197
- rewardApr: spool?.stakeApr ?? 0,
216
+ rewardApr: spool?.rewardApr ?? 0,
198
217
  suppliedAmount: suppliedAmount.plus(stakedAmount).toNumber(),
199
218
  suppliedCoin: suppliedCoin.plus(stakedCoin).toNumber(),
200
219
  suppliedValue: suppliedValue.plus(stakedValue).toNumber(),
@@ -203,11 +222,21 @@ export const getLending = async (
203
222
  stakedAmount: stakedAmount.toNumber(),
204
223
  stakedCoin: stakedCoin.toNumber(),
205
224
  stakedValue: stakedValue.toNumber(),
206
- availableSupplyAmount: coinAmount,
207
- availableWithdrawAmount: 0,
208
- availableStakeAmount: marketCoinAmount,
225
+ unstakedMarketAmount: unstakedMarketAmount.toNumber(),
226
+ unstakedMarketCoin: unstakedMarketCoin.toNumber(),
227
+ unstakedAmount: suppliedAmount.toNumber(),
228
+ unstakedCoin: suppliedCoin.toNumber(),
229
+ unstakedValue: suppliedValue.toNumber(),
230
+ availableSupplyAmount: availableSupplyAmount.toNumber(),
231
+ availableSupplyCoin: availableSupplyCoin.toNumber(),
232
+ availableWithdrawAmount: availableWithdrawAmount.toNumber(),
233
+ availableWithdrawCoin: availableWithdrawCoin.toNumber(),
234
+ availableStakeAmount: unstakedMarketAmount.toNumber(),
235
+ availableStakeCoin: unstakedMarketCoin.toNumber(),
209
236
  availableUnstakeAmount: availableUnstakeAmount.toNumber(),
237
+ availableUnstakeCoin: availableUnstakeCoin.toNumber(),
210
238
  availableClaimAmount: availableClaimAmount.toNumber(),
239
+ availableClaimCoin: availableClaimCoin.toNumber(),
211
240
  };
212
241
 
213
242
  return lending;
@@ -323,6 +352,8 @@ export const getObligationAccount = async (
323
352
  coinName: collateralCoinName,
324
353
  coinType: collateral.type.name,
325
354
  symbol: query.utils.parseSymbol(collateralCoinName),
355
+ coinDecimal: coinDecimal,
356
+ coinPrice: coinPrice,
326
357
  depositedAmount: depositedAmount.toNumber(),
327
358
  depositedCoin: depositedCoin.toNumber(),
328
359
  depositedValue: depositedValue.toNumber(),
@@ -373,6 +404,8 @@ export const getObligationAccount = async (
373
404
  coinName: poolCoinName,
374
405
  coinType: debt.type.name,
375
406
  symbol: query.utils.parseSymbol(poolCoinName),
407
+ coinDecimal: coinDecimal,
408
+ coinPrice: coinPrice,
376
409
  borrowedAmount: borrowedAmount.toNumber(),
377
410
  borrowedCoin: borrowedCoin.toNumber(),
378
411
  borrowedValue: borrowedValue.toNumber(),
@@ -449,8 +482,8 @@ export const getObligationAccount = async (
449
482
  if (marketCollateral) {
450
483
  const availableWithdrawAmount =
451
484
  obligationAccount.totalBorrowedValueWithWeight === 0
452
- ? obligationCollateral.depositedAmount
453
- : Math.min(
485
+ ? BigNumber(obligationCollateral.depositedAmount)
486
+ : minBigNumber(
454
487
  BigNumber(obligationAccount.totalAvailableCollateralValue)
455
488
  .dividedBy(marketCollateral.collateralFactor)
456
489
  .dividedBy(marketCollateral.coinPrice)
@@ -460,8 +493,11 @@ export const getObligationAccount = async (
460
493
  obligationCollateral.depositedAmount,
461
494
  marketCollateral.depositAmount
462
495
  );
463
- obligationCollateral.availableWithdrawAmount = availableWithdrawAmount;
464
- obligationCollateral.availableWithdrawCoin = availableWithdrawAmount;
496
+ obligationCollateral.availableWithdrawAmount =
497
+ availableWithdrawAmount.toNumber();
498
+ obligationCollateral.availableWithdrawCoin = availableWithdrawAmount
499
+ .shiftedBy(-1 * obligationCollateral.coinDecimal)
500
+ .toNumber();
465
501
  }
466
502
  }
467
503
  for (const [assetCoinName, obligationDebt] of Object.entries(
@@ -473,12 +509,11 @@ export const getObligationAccount = async (
473
509
  obligationDebt.availableRepayAmount
474
510
  )
475
511
  // Note: reduced chance of failure when calculations are inaccurate
476
- .multipliedBy(1.01)
477
- .toNumber();
512
+ .multipliedBy(1.01);
478
513
 
479
514
  const availableBorrowAmount =
480
515
  obligationAccount.totalAvailableCollateralValue !== 0
481
- ? Math.min(
516
+ ? minBigNumber(
482
517
  BigNumber(obligationAccount.totalAvailableCollateralValue)
483
518
  .dividedBy(
484
519
  BigNumber(marketPool.coinPrice).multipliedBy(
@@ -490,9 +525,15 @@ export const getObligationAccount = async (
490
525
  .toNumber(),
491
526
  marketPool.supplyAmount
492
527
  )
493
- : 0;
494
- obligationDebt.availableBorrowAmount = availableBorrowAmount;
495
- obligationDebt.availableRepayAmount = availableRepayAmount;
528
+ : BigNumber(0);
529
+ obligationDebt.availableBorrowAmount = availableBorrowAmount.toNumber();
530
+ obligationDebt.availableBorrowCoin = availableBorrowAmount
531
+ .shiftedBy(-1 * obligationDebt.coinDecimal)
532
+ .toNumber();
533
+ obligationDebt.availableRepayAmount = availableRepayAmount.toNumber();
534
+ obligationDebt.availableRepayCoin = availableRepayAmount
535
+ .shiftedBy(-1 * obligationDebt.coinDecimal)
536
+ .toNumber();
496
537
  }
497
538
  }
498
539
 
@@ -25,3 +25,16 @@ export type StakeMarketCoins = {
25
25
  export type RewardCoins = {
26
26
  [key in SupportStakeMarketCoins]: SupportRewardCoins;
27
27
  };
28
+
29
+ export type AssetCoinIds = {
30
+ [key in SupportAssetCoins]: string;
31
+ };
32
+
33
+ type PickFromUnion<T, K extends string> = K extends T ? K : never;
34
+
35
+ export type WormholeCoinIds = {
36
+ [key in PickFromUnion<
37
+ SupportAssetCoins,
38
+ 'eth' | 'btc' | 'usdc' | 'usdt' | 'apt' | 'sol'
39
+ >]: string;
40
+ };
@@ -123,6 +123,8 @@ export type MarketPool = {
123
123
  } & Required<
124
124
  Pick<
125
125
  ParsedMarketPoolData,
126
+ | 'highKink'
127
+ | 'midKink'
126
128
  | 'reserveFactor'
127
129
  | 'borrowWeight'
128
130
  | 'marketCoinSupplyAmount'
@@ -32,11 +32,21 @@ export type Lending = Required<
32
32
  stakedAmount: number;
33
33
  stakedCoin: number;
34
34
  stakedValue: number;
35
+ unstakedMarketAmount: number;
36
+ unstakedMarketCoin: number;
37
+ unstakedAmount: number;
38
+ unstakedCoin: number;
39
+ unstakedValue: number;
35
40
  availableSupplyAmount: number;
41
+ availableSupplyCoin: number;
36
42
  availableWithdrawAmount: number;
43
+ availableWithdrawCoin: number;
37
44
  availableStakeAmount: number;
45
+ availableStakeCoin: number;
38
46
  availableUnstakeAmount: number;
47
+ availableUnstakeCoin: number;
39
48
  availableClaimAmount: number;
49
+ availableClaimCoin: number;
40
50
  };
41
51
 
42
52
  export type ObligationAccount = {
@@ -53,43 +63,43 @@ export type ObligationAccount = {
53
63
  totalDepositedPools: number;
54
64
  totalBorrowedPools: number;
55
65
  collaterals: OptionalKeys<
56
- Record<
57
- SupportCollateralCoins,
58
- {
59
- coinName: SupportCollateralCoins;
60
- coinType: string;
61
- symbol: string;
62
- depositedAmount: number;
63
- depositedCoin: number;
64
- depositedValue: number;
65
- borrowCapacityValue: number;
66
- requiredCollateralValue: number;
67
- availableDepositAmount: number;
68
- availableDepositCoin: number;
69
- availableWithdrawAmount: number;
70
- availableWithdrawCoin: number;
71
- }
72
- >
73
- >;
74
- debts: OptionalKeys<
75
- Record<
76
- SupportPoolCoins,
77
- {
78
- coinName: SupportPoolCoins;
79
- coinType: string;
80
- symbol: string;
81
- borrowedAmount: number;
82
- borrowedCoin: number;
83
- borrowedValue: number;
84
- borrowedValueWithWeight: number;
85
- borrowIndex: number;
86
- availableBorrowAmount: number;
87
- availableBorrowCoin: number;
88
- availableRepayAmount: number;
89
- availableRepayCoin: number;
90
- }
91
- >
66
+ Record<SupportCollateralCoins, ObligationCollateral>
92
67
  >;
68
+ debts: OptionalKeys<Record<SupportPoolCoins, ObligationDebt>>;
69
+ };
70
+
71
+ export type ObligationCollateral = {
72
+ coinName: SupportCollateralCoins;
73
+ coinType: string;
74
+ symbol: string;
75
+ coinDecimal: number;
76
+ coinPrice: number;
77
+ depositedAmount: number;
78
+ depositedCoin: number;
79
+ depositedValue: number;
80
+ borrowCapacityValue: number;
81
+ requiredCollateralValue: number;
82
+ availableDepositAmount: number;
83
+ availableDepositCoin: number;
84
+ availableWithdrawAmount: number;
85
+ availableWithdrawCoin: number;
86
+ };
87
+
88
+ export type ObligationDebt = {
89
+ coinName: SupportPoolCoins;
90
+ coinType: string;
91
+ symbol: string;
92
+ coinDecimal: number;
93
+ coinPrice: number;
94
+ borrowedAmount: number;
95
+ borrowedCoin: number;
96
+ borrowedValue: number;
97
+ borrowedValueWithWeight: number;
98
+ borrowIndex: number;
99
+ availableBorrowAmount: number;
100
+ availableBorrowCoin: number;
101
+ availableRepayAmount: number;
102
+ availableRepayCoin: number;
93
103
  };
94
104
 
95
105
  export type TotalValueLocked = {
@@ -82,7 +82,7 @@ export type ParsedRewardPoolData = {
82
82
  };
83
83
 
84
84
  export type CalculatedRewardPoolData = {
85
- stakeApr: number;
85
+ rewardApr: number;
86
86
  totalRewardAmount: number;
87
87
  totalRewardCoin: number;
88
88
  totalRewardValue: number;
@@ -346,7 +346,7 @@ export const calculateRewardPoolData = (
346
346
  .shiftedBy(-1 * rewardCoinDecimal)
347
347
  .multipliedBy(rateYearFactor)
348
348
  .multipliedBy(rewardCoinPrice);
349
- const stakeRate = rewardValueForYear
349
+ const rewardRate = rewardValueForYear
350
350
  .dividedBy(calculatedStakePoolData.stakedValue)
351
351
  .isFinite()
352
352
  ? rewardValueForYear
@@ -355,7 +355,7 @@ export const calculateRewardPoolData = (
355
355
  : Infinity;
356
356
 
357
357
  return {
358
- stakeApr: stakeRate,
358
+ rewardApr: rewardRate,
359
359
  totalRewardAmount: totalRewardAmount.toNumber(),
360
360
  totalRewardCoin: totalRewardCoin.toNumber(),
361
361
  totalRewardValue: totalRewardValue.toNumber(),
@@ -370,3 +370,19 @@ export const calculateRewardPoolData = (
370
370
  exchangeRateDenominator: parsedRewardPoolData.exchangeRateDenominator,
371
371
  };
372
372
  };
373
+
374
+ export const minBigNumber = (...args: BigNumber.Value[]) => {
375
+ return BigNumber(
376
+ args.reduce((min, current) =>
377
+ new BigNumber(current).lt(min) ? current : min
378
+ )
379
+ );
380
+ };
381
+
382
+ export const maxBigNumber = (...args: BigNumber.Value[]) => {
383
+ return BigNumber(
384
+ args.reduce((max, current) =>
385
+ new BigNumber(current).gt(max) ? current : max
386
+ )
387
+ );
388
+ };