@scallop-io/sui-scallop-sdk 1.3.41 → 1.4.1-alpha.1
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.
- package/dist/constants/common.d.ts +3 -3
- package/dist/constants/enum.d.ts +2 -2
- package/dist/constants/tokenBucket.d.ts +1 -1
- package/dist/index.js +412 -334
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +411 -333
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopClient.d.ts +4 -4
- package/dist/models/scallopQuery.d.ts +74 -20
- package/dist/models/scallopUtils.d.ts +11 -11
- package/dist/queries/borrowIncentiveQuery.d.ts +2 -2
- package/dist/queries/coreQuery.d.ts +0 -2
- package/dist/queries/portfolioQuery.d.ts +0 -2
- package/dist/queries/priceQuery.d.ts +32 -2
- package/dist/queries/sCoinQuery.d.ts +1 -1
- package/dist/test.d.ts +0 -0
- package/dist/types/builder/borrowIncentive.d.ts +6 -6
- package/dist/types/constant/common.d.ts +1 -1
- package/dist/types/utils.d.ts +2 -6
- package/package.json +1 -1
- package/src/builders/borrowIncentiveBuilder.ts +2 -13
- package/src/constants/coinGecko.ts +3 -2
- package/src/constants/common.ts +10 -5
- package/src/constants/enum.ts +44 -34
- package/src/constants/poolAddress.ts +9 -8
- package/src/constants/pyth.ts +3 -2
- package/src/constants/tokenBucket.ts +1 -1
- package/src/models/scallopClient.ts +27 -10
- package/src/models/scallopQuery.ts +55 -31
- package/src/models/scallopUtils.ts +23 -18
- package/src/queries/borrowIncentiveQuery.ts +29 -12
- package/src/queries/borrowLimitQuery.ts +3 -2
- package/src/queries/coreQuery.ts +185 -196
- package/src/queries/isolatedAssetQuery.ts +3 -2
- package/src/queries/portfolioQuery.ts +81 -77
- package/src/queries/priceQuery.ts +35 -2
- package/src/queries/sCoinQuery.ts +3 -3
- package/src/queries/spoolQuery.ts +4 -6
- package/src/queries/supplyLimitQuery.ts +3 -2
- package/src/test.ts +20 -0
- package/src/types/builder/borrowIncentive.ts +10 -15
- package/src/types/constant/common.ts +1 -2
- package/src/types/utils.ts +2 -10
- package/src/utils/indexer.ts +9 -3
- package/src/utils/query.ts +0 -87
- package/src/utils/tokenBucket.ts +2 -2
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js';
|
|
2
2
|
import {
|
|
3
|
-
SUPPORT_BORROW_INCENTIVE_REWARDS,
|
|
4
3
|
SUPPORT_COLLATERALS,
|
|
5
4
|
SUPPORT_POOLS,
|
|
6
5
|
SUPPORT_SPOOLS,
|
|
@@ -50,11 +49,13 @@ export const getLendings = async (
|
|
|
50
49
|
(SUPPORT_SPOOLS as readonly SupportMarketCoins[]).includes(marketCoinName)
|
|
51
50
|
) as SupportStakeMarketCoins[];
|
|
52
51
|
|
|
53
|
-
const coinPrices = await query.utils.getCoinPrices(
|
|
54
|
-
const marketPools = await query.getMarketPools(poolCoinNames,
|
|
52
|
+
const coinPrices = await query.utils.getCoinPrices();
|
|
53
|
+
const marketPools = await query.getMarketPools(poolCoinNames, {
|
|
54
|
+
indexer,
|
|
55
55
|
coinPrices,
|
|
56
56
|
});
|
|
57
|
-
const spools = await query.getSpools(stakeMarketCoinNames,
|
|
57
|
+
const spools = await query.getSpools(stakeMarketCoinNames, {
|
|
58
|
+
indexer,
|
|
58
59
|
marketPools,
|
|
59
60
|
coinPrices,
|
|
60
61
|
});
|
|
@@ -122,13 +123,12 @@ export const getLending = async (
|
|
|
122
123
|
) => {
|
|
123
124
|
const marketCoinName = query.utils.parseMarketCoinName(poolCoinName);
|
|
124
125
|
coinPrice =
|
|
125
|
-
coinPrice ??
|
|
126
|
-
(await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName] ??
|
|
127
|
-
0;
|
|
126
|
+
coinPrice ?? (await query.utils.getCoinPrices())?.[poolCoinName] ?? 0;
|
|
128
127
|
|
|
129
128
|
marketPool =
|
|
130
129
|
marketPool ??
|
|
131
|
-
(await query.getMarketPool(poolCoinName,
|
|
130
|
+
(await query.getMarketPool(poolCoinName, {
|
|
131
|
+
indexer,
|
|
132
132
|
coinPrice,
|
|
133
133
|
}));
|
|
134
134
|
|
|
@@ -138,16 +138,13 @@ export const getLending = async (
|
|
|
138
138
|
spool =
|
|
139
139
|
(spool ??
|
|
140
140
|
(SUPPORT_SPOOLS as readonly SupportMarketCoins[]).includes(marketCoinName))
|
|
141
|
-
? await query.getSpool(
|
|
142
|
-
marketCoinName as SupportStakeMarketCoins,
|
|
141
|
+
? await query.getSpool(marketCoinName as SupportStakeMarketCoins, {
|
|
143
142
|
indexer,
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
)
|
|
143
|
+
marketPool,
|
|
144
|
+
coinPrices: {
|
|
145
|
+
[poolCoinName]: coinPrice,
|
|
146
|
+
},
|
|
147
|
+
})
|
|
151
148
|
: undefined;
|
|
152
149
|
// some pool does not have spool
|
|
153
150
|
// if (!spool) throw new Error(`Failed to fetch spool for ${poolCoinName}`);
|
|
@@ -311,7 +308,7 @@ export const getObligationAccounts = async (
|
|
|
311
308
|
indexer: boolean = false
|
|
312
309
|
) => {
|
|
313
310
|
const coinPrices = await query.utils.getCoinPrices();
|
|
314
|
-
const market = await query.queryMarket(indexer,
|
|
311
|
+
const market = await query.queryMarket({ indexer, coinPrices });
|
|
315
312
|
const [coinAmounts, obligations] = await Promise.all([
|
|
316
313
|
query.getCoinAmounts(undefined, ownerAddress),
|
|
317
314
|
query.getObligations(ownerAddress),
|
|
@@ -355,9 +352,9 @@ export const getObligationAccount = async (
|
|
|
355
352
|
const collateralAssetCoinNames: SupportCollateralCoins[] = [
|
|
356
353
|
...SUPPORT_COLLATERALS,
|
|
357
354
|
];
|
|
355
|
+
market = market ?? (await query.queryMarket({ indexer }));
|
|
358
356
|
coinPrices =
|
|
359
|
-
coinPrices ?? (await query.
|
|
360
|
-
market = market ?? (await query.queryMarket(indexer, { coinPrices }));
|
|
357
|
+
coinPrices ?? (await query.getAllCoinPrices({ marketPools: market.pools }));
|
|
361
358
|
coinAmounts =
|
|
362
359
|
coinAmounts ||
|
|
363
360
|
(await query.getCoinAmounts(collateralAssetCoinNames, ownerAddress));
|
|
@@ -365,8 +362,9 @@ export const getObligationAccount = async (
|
|
|
365
362
|
const [obligationQuery, borrowIncentivePools, borrowIncentiveAccounts] =
|
|
366
363
|
await Promise.all([
|
|
367
364
|
query.queryObligation(obligationId),
|
|
368
|
-
query.getBorrowIncentivePools(undefined,
|
|
365
|
+
query.getBorrowIncentivePools(undefined, {
|
|
369
366
|
coinPrices,
|
|
367
|
+
indexer,
|
|
370
368
|
}),
|
|
371
369
|
query.getBorrowIncentiveAccounts(obligationId),
|
|
372
370
|
]);
|
|
@@ -525,64 +523,70 @@ export const getObligationAccount = async (
|
|
|
525
523
|
const borrowIncentivePool = borrowIncentivePools[coinName];
|
|
526
524
|
if (borrowIncentivePool) {
|
|
527
525
|
const rewards: ObligationBorrowIcentiveReward[] = [];
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
.plus(accountPoint.points)
|
|
549
|
-
);
|
|
550
|
-
availableClaimCoin = availableClaimAmount.shiftedBy(
|
|
551
|
-
-1 * poolPoint.coinDecimal
|
|
552
|
-
);
|
|
553
|
-
|
|
554
|
-
// for veSCA
|
|
555
|
-
const weightScale = BigNumber(1_000_000_000_000);
|
|
556
|
-
const boostValue = BigNumber(accountPoint.weightedAmount)
|
|
557
|
-
.div(
|
|
558
|
-
BigNumber(borrowIncentiveAccount.debtAmount)
|
|
559
|
-
.multipliedBy(poolPoint.baseWeight)
|
|
560
|
-
.dividedBy(weightScale)
|
|
561
|
-
)
|
|
562
|
-
.isFinite()
|
|
563
|
-
? BigNumber(accountPoint.weightedAmount)
|
|
564
|
-
.div(
|
|
565
|
-
BigNumber(borrowIncentiveAccount.debtAmount)
|
|
566
|
-
.multipliedBy(poolPoint.baseWeight)
|
|
567
|
-
.dividedBy(weightScale)
|
|
526
|
+
Object.entries(borrowIncentiveAccount.pointList).forEach(
|
|
527
|
+
([key, accountPoint]) => {
|
|
528
|
+
const poolPoint =
|
|
529
|
+
borrowIncentivePool.points[
|
|
530
|
+
key as SupportBorrowIncentiveRewardCoins
|
|
531
|
+
];
|
|
532
|
+
|
|
533
|
+
if (accountPoint && poolPoint) {
|
|
534
|
+
let availableClaimAmount = BigNumber(0);
|
|
535
|
+
let availableClaimCoin = BigNumber(0);
|
|
536
|
+
const accountBorrowedAmount = BigNumber(
|
|
537
|
+
accountPoint.weightedAmount
|
|
538
|
+
);
|
|
539
|
+
const baseIndexRate = 1_000_000_000;
|
|
540
|
+
const increasedPointRate = poolPoint.currentPointIndex
|
|
541
|
+
? Math.max(
|
|
542
|
+
BigNumber(poolPoint.currentPointIndex - accountPoint.index)
|
|
543
|
+
.dividedBy(baseIndexRate)
|
|
544
|
+
.toNumber(),
|
|
545
|
+
0
|
|
568
546
|
)
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
547
|
+
: 1;
|
|
548
|
+
availableClaimAmount = availableClaimAmount.plus(
|
|
549
|
+
accountBorrowedAmount
|
|
550
|
+
.multipliedBy(increasedPointRate)
|
|
551
|
+
.plus(accountPoint.points)
|
|
552
|
+
);
|
|
553
|
+
availableClaimCoin = availableClaimAmount.shiftedBy(
|
|
554
|
+
-1 * poolPoint.coinDecimal
|
|
555
|
+
);
|
|
556
|
+
|
|
557
|
+
// for veSCA
|
|
558
|
+
const weightScale = BigNumber(1_000_000_000_000);
|
|
559
|
+
const boostValue = BigNumber(accountPoint.weightedAmount)
|
|
560
|
+
.div(
|
|
561
|
+
BigNumber(borrowIncentiveAccount.debtAmount)
|
|
562
|
+
.multipliedBy(poolPoint.baseWeight)
|
|
563
|
+
.dividedBy(weightScale)
|
|
564
|
+
)
|
|
565
|
+
.isFinite()
|
|
566
|
+
? BigNumber(accountPoint.weightedAmount)
|
|
567
|
+
.div(
|
|
568
|
+
BigNumber(borrowIncentiveAccount.debtAmount)
|
|
569
|
+
.multipliedBy(poolPoint.baseWeight)
|
|
570
|
+
.dividedBy(weightScale)
|
|
571
|
+
)
|
|
572
|
+
.toNumber()
|
|
573
|
+
: 1;
|
|
574
|
+
|
|
575
|
+
if (availableClaimAmount.isGreaterThanOrEqualTo(0)) {
|
|
576
|
+
rewards.push({
|
|
577
|
+
coinName: poolPoint.coinName,
|
|
578
|
+
coinType: poolPoint.coinType,
|
|
579
|
+
symbol: poolPoint.symbol,
|
|
580
|
+
coinDecimal: poolPoint.coinDecimal,
|
|
581
|
+
coinPrice: poolPoint.coinPrice,
|
|
582
|
+
availableClaimAmount: availableClaimAmount.toNumber(),
|
|
583
|
+
availableClaimCoin: availableClaimCoin.toNumber(),
|
|
584
|
+
boostValue,
|
|
585
|
+
});
|
|
586
|
+
}
|
|
583
587
|
}
|
|
584
588
|
}
|
|
585
|
-
|
|
589
|
+
);
|
|
586
590
|
|
|
587
591
|
if (
|
|
588
592
|
Object.keys(borrowIncentivePool.points).some((coinName: any) => {
|
|
@@ -770,7 +774,7 @@ export const getTotalValueLocked = async (
|
|
|
770
774
|
query: ScallopQuery,
|
|
771
775
|
indexer: boolean = false
|
|
772
776
|
) => {
|
|
773
|
-
const market = await query.queryMarket(indexer);
|
|
777
|
+
const market = await query.queryMarket({ indexer });
|
|
774
778
|
|
|
775
779
|
let supplyValue = BigNumber(0);
|
|
776
780
|
let borrowValue = BigNumber(0);
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { SuiObjectData } from '@mysten/sui/client';
|
|
2
|
-
import type { ScallopAddress } from '../models';
|
|
3
|
-
import type {
|
|
2
|
+
import type { ScallopAddress, ScallopQuery } from '../models';
|
|
3
|
+
import type {
|
|
4
|
+
CoinPrices,
|
|
5
|
+
MarketPools,
|
|
6
|
+
OptionalKeys,
|
|
7
|
+
SupportAssetCoins,
|
|
8
|
+
SupportSCoin,
|
|
9
|
+
} from '../types';
|
|
10
|
+
import { SUPPORT_SCOIN } from 'src/constants/common';
|
|
11
|
+
import BigNumber from 'bignumber.js';
|
|
4
12
|
|
|
5
13
|
/**
|
|
6
14
|
* Get price from pyth fee object.
|
|
@@ -126,3 +134,28 @@ export const getPythPrices = async (
|
|
|
126
134
|
{} as Record<SupportAssetCoins, number>
|
|
127
135
|
);
|
|
128
136
|
};
|
|
137
|
+
|
|
138
|
+
export const getAllCoinPrices = async (
|
|
139
|
+
query: ScallopQuery,
|
|
140
|
+
marketPools?: MarketPools,
|
|
141
|
+
coinPrices?: CoinPrices
|
|
142
|
+
) => {
|
|
143
|
+
coinPrices = coinPrices ?? (await query.utils.getCoinPrices());
|
|
144
|
+
marketPools =
|
|
145
|
+
marketPools ?? (await query.getMarketPools(undefined, { coinPrices }));
|
|
146
|
+
if (!marketPools) {
|
|
147
|
+
throw new Error(`Failed to fetch market pool for getAllCoinPrices`);
|
|
148
|
+
}
|
|
149
|
+
const sCoinPrices: OptionalKeys<Record<SupportSCoin, number>> = {};
|
|
150
|
+
SUPPORT_SCOIN.forEach((sCoinName) => {
|
|
151
|
+
const coinName = query.utils.parseCoinName(sCoinName);
|
|
152
|
+
sCoinPrices[sCoinName] = BigNumber(coinPrices[coinName] ?? 0)
|
|
153
|
+
.multipliedBy(marketPools[coinName]?.conversionRate ?? 1)
|
|
154
|
+
.toNumber();
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
...coinPrices,
|
|
159
|
+
...sCoinPrices,
|
|
160
|
+
};
|
|
161
|
+
};
|
|
@@ -139,8 +139,8 @@ export const getSCoinSwapRate = async (
|
|
|
139
139
|
|
|
140
140
|
// Get lending data for both sCoin A and sCoin B
|
|
141
141
|
const marketPools = await Promise.all([
|
|
142
|
-
query.getMarketPool(fromCoinName
|
|
143
|
-
query.getMarketPool(toCoinName
|
|
142
|
+
query.getMarketPool(fromCoinName),
|
|
143
|
+
query.getMarketPool(toCoinName),
|
|
144
144
|
]);
|
|
145
145
|
if (marketPools.some((pool) => !pool))
|
|
146
146
|
throw new Error('Failed to fetch the lendings data');
|
|
@@ -153,7 +153,7 @@ export const getSCoinSwapRate = async (
|
|
|
153
153
|
const BtoSCoinBRate = 1 / marketPools[1]!.conversionRate;
|
|
154
154
|
|
|
155
155
|
const calcAtoBRate = async () => {
|
|
156
|
-
const prices = await query.utils.getCoinPrices(
|
|
156
|
+
const prices = await query.utils.getCoinPrices();
|
|
157
157
|
if (!prices[fromCoinName] || !prices[toCoinName]) {
|
|
158
158
|
throw new Error('Failed to fetch the coin prices');
|
|
159
159
|
}
|
|
@@ -43,7 +43,7 @@ export const getSpools = async (
|
|
|
43
43
|
coinPrices = coinPrices ?? (await query.utils.getCoinPrices()) ?? {};
|
|
44
44
|
|
|
45
45
|
marketPools =
|
|
46
|
-
marketPools ?? (await query.getMarketPools(stakeCoinNames, indexer));
|
|
46
|
+
marketPools ?? (await query.getMarketPools(stakeCoinNames, { indexer }));
|
|
47
47
|
if (!marketPools)
|
|
48
48
|
throw new Error(`Fail to fetch marketPools for ${stakeCoinNames}`);
|
|
49
49
|
|
|
@@ -71,7 +71,6 @@ export const getSpools = async (
|
|
|
71
71
|
};
|
|
72
72
|
Object.values(spoolsIndexer).forEach(updateSpools);
|
|
73
73
|
|
|
74
|
-
// console.log(spools);
|
|
75
74
|
return spools;
|
|
76
75
|
}
|
|
77
76
|
|
|
@@ -112,7 +111,7 @@ export const getSpool = async (
|
|
|
112
111
|
coinPrices?: CoinPrices
|
|
113
112
|
) => {
|
|
114
113
|
const coinName = query.utils.parseCoinName<SupportStakeCoins>(marketCoinName);
|
|
115
|
-
marketPool = marketPool || (await query.getMarketPool(coinName, indexer));
|
|
114
|
+
marketPool = marketPool || (await query.getMarketPool(coinName, { indexer }));
|
|
116
115
|
if (!marketPool) {
|
|
117
116
|
throw new Error(`Failed to fetch marketPool for ${marketCoinName}`);
|
|
118
117
|
}
|
|
@@ -122,7 +121,7 @@ export const getSpool = async (
|
|
|
122
121
|
`spool.pools.${marketCoinName}.rewardPoolId`
|
|
123
122
|
);
|
|
124
123
|
let spool: Spool | undefined = undefined;
|
|
125
|
-
coinPrices = coinPrices || (await query.utils.getCoinPrices(
|
|
124
|
+
coinPrices = coinPrices || (await query.utils.getCoinPrices());
|
|
126
125
|
|
|
127
126
|
if (indexer) {
|
|
128
127
|
const spoolIndexer = await query.indexer.getSpool(marketCoinName);
|
|
@@ -152,8 +151,7 @@ export const getSpool = async (
|
|
|
152
151
|
}
|
|
153
152
|
|
|
154
153
|
const rewardCoinName = query.utils.getSpoolRewardCoinName(marketCoinName);
|
|
155
|
-
coinPrices =
|
|
156
|
-
coinPrices || (await query.utils.getCoinPrices([coinName, rewardCoinName]));
|
|
154
|
+
coinPrices = coinPrices || (await query.utils.getCoinPrices());
|
|
157
155
|
|
|
158
156
|
const spoolObject = spoolObjectResponse[0];
|
|
159
157
|
const rewardPoolObject = spoolObjectResponse[1];
|
|
@@ -17,8 +17,9 @@ const supplyLimitZod = zod.object({
|
|
|
17
17
|
}),
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
// const supplyLimitKeyType = `
|
|
20
|
+
// TODO: enable for production
|
|
21
|
+
// const supplyLimitKeyType = `0x6e641f0dca8aedab3101d047e96439178f16301bf0b57fe8745086ff1195eb3e::market_dynamic_keys::SupplyLimitKey`; // prod
|
|
22
|
+
const supplyLimitKeyType = `0x6c23585e940a989588432509107e98bae06dbca4e333f26d0635d401b3c7c76d::market_dynamic_keys::SupplyLimitKey`;
|
|
22
23
|
/**
|
|
23
24
|
* Return supply limit of a pool (including the decimals)
|
|
24
25
|
* @param utils
|
package/src/test.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// import { ScallopQuery } from './models';
|
|
2
|
+
|
|
3
|
+
// const main = async () => {
|
|
4
|
+
// try {
|
|
5
|
+
// const query = new ScallopQuery({
|
|
6
|
+
// walletAddress:
|
|
7
|
+
// '0x61819c99588108d9f7710047e6ad8f2da598de8e98a26ea62bd7ad9847f5329c',
|
|
8
|
+
// });
|
|
9
|
+
// await query.init();
|
|
10
|
+
|
|
11
|
+
// const res = await query.getAllCoinPrices();
|
|
12
|
+
// console.dir(res, { depth: null });
|
|
13
|
+
// } catch (e) {
|
|
14
|
+
// console.error(e);
|
|
15
|
+
// } finally {
|
|
16
|
+
// process.exit(0);
|
|
17
|
+
// }
|
|
18
|
+
// };
|
|
19
|
+
|
|
20
|
+
// main();
|
|
@@ -4,10 +4,7 @@ import type {
|
|
|
4
4
|
} from '@scallop-io/sui-kit';
|
|
5
5
|
import type { TransactionResult } from '@mysten/sui/transactions';
|
|
6
6
|
import type { ScallopBuilder } from '../../models';
|
|
7
|
-
import type {
|
|
8
|
-
SupportBorrowIncentiveCoins,
|
|
9
|
-
SupportBorrowIncentiveRewardCoins,
|
|
10
|
-
} from '../constant';
|
|
7
|
+
import type { SupportBorrowIncentiveRewardCoins } from '../constant';
|
|
11
8
|
|
|
12
9
|
export type BorrowIncentiveIds = {
|
|
13
10
|
borrowIncentivePkg: string;
|
|
@@ -35,7 +32,6 @@ export type BorrowIncentiveNormalMethods = {
|
|
|
35
32
|
claimBorrowIncentive: (
|
|
36
33
|
obligation: SuiObjectArg,
|
|
37
34
|
obligationKey: SuiObjectArg,
|
|
38
|
-
coinName: SupportBorrowIncentiveCoins,
|
|
39
35
|
rewardType: SupportBorrowIncentiveRewardCoins
|
|
40
36
|
) => TransactionResult;
|
|
41
37
|
deactivateBoost: (obligation: SuiObjectArg, veScaKey: SuiObjectArg) => void;
|
|
@@ -43,23 +39,22 @@ export type BorrowIncentiveNormalMethods = {
|
|
|
43
39
|
|
|
44
40
|
export type BorrowIncentiveQuickMethods = {
|
|
45
41
|
stakeObligationQuick(
|
|
46
|
-
obligation?:
|
|
47
|
-
obligationKey?:
|
|
42
|
+
obligation?: string,
|
|
43
|
+
obligationKey?: string
|
|
48
44
|
): Promise<void>;
|
|
49
45
|
stakeObligationWithVeScaQuick(
|
|
50
|
-
obligation?:
|
|
51
|
-
obligationKey?:
|
|
52
|
-
veScaKey?:
|
|
46
|
+
obligation?: string,
|
|
47
|
+
obligationKey?: string,
|
|
48
|
+
veScaKey?: string
|
|
53
49
|
): Promise<void>;
|
|
54
50
|
unstakeObligationQuick(
|
|
55
|
-
obligation?:
|
|
56
|
-
obligationKey?:
|
|
51
|
+
obligation?: string,
|
|
52
|
+
obligationKey?: string
|
|
57
53
|
): Promise<void>;
|
|
58
54
|
claimBorrowIncentiveQuick(
|
|
59
|
-
coinName: SupportBorrowIncentiveCoins,
|
|
60
55
|
rewardType: SupportBorrowIncentiveRewardCoins,
|
|
61
|
-
obligation?:
|
|
62
|
-
obligationKey?:
|
|
56
|
+
obligation?: string,
|
|
57
|
+
obligationKey?: string
|
|
63
58
|
): Promise<TransactionResult>;
|
|
64
59
|
};
|
|
65
60
|
|
|
@@ -23,8 +23,7 @@ export type SupportCoins =
|
|
|
23
23
|
export type SupportAssetCoins =
|
|
24
24
|
| SupportPoolCoins
|
|
25
25
|
| SupportCollateralCoins
|
|
26
|
-
| SupportStakeRewardCoins
|
|
27
|
-
| SupportBorrowIncentiveRewardCoins;
|
|
26
|
+
| SupportStakeRewardCoins;
|
|
28
27
|
export type SupportPoolCoins = (typeof SUPPORT_POOLS)[number];
|
|
29
28
|
export type SupportCollateralCoins = (typeof SUPPORT_COLLATERALS)[number];
|
|
30
29
|
export type SupportMarketCoins =
|
package/src/types/utils.ts
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SupportCoins } from './constant';
|
|
2
2
|
|
|
3
3
|
export type OptionalKeys<T> = {
|
|
4
4
|
[K in keyof T]?: T[K];
|
|
5
5
|
};
|
|
6
6
|
|
|
7
|
-
export type CoinPrices = OptionalKeys<Record<
|
|
8
|
-
|
|
9
|
-
export type PriceMap = Map<
|
|
10
|
-
SupportAssetCoins,
|
|
11
|
-
{
|
|
12
|
-
price: number;
|
|
13
|
-
publishTime: number;
|
|
14
|
-
}
|
|
15
|
-
>;
|
|
7
|
+
export type CoinPrices = OptionalKeys<Record<SupportCoins, number>>;
|
|
16
8
|
|
|
17
9
|
export type PoolAddressInfo = {
|
|
18
10
|
name: string;
|
package/src/utils/indexer.ts
CHANGED
|
@@ -11,14 +11,20 @@ export async function callMethodWithIndexerFallback(
|
|
|
11
11
|
context: any,
|
|
12
12
|
...args: any[]
|
|
13
13
|
) {
|
|
14
|
-
const
|
|
14
|
+
const lastArgs = args[args.length - 1]; // Assume last argument is always `indexer`
|
|
15
15
|
|
|
16
|
-
if (indexer) {
|
|
16
|
+
if (typeof lastArgs === 'object' && lastArgs.indexer) {
|
|
17
17
|
try {
|
|
18
18
|
return await method.apply(context, args);
|
|
19
19
|
} catch (e: any) {
|
|
20
20
|
console.warn(`Indexer requests failed: ${e}. Retrying without indexer..`);
|
|
21
|
-
return await method.apply(context, [
|
|
21
|
+
return await method.apply(context, [
|
|
22
|
+
...args.slice(0, -1),
|
|
23
|
+
{
|
|
24
|
+
...lastArgs,
|
|
25
|
+
indexer: false,
|
|
26
|
+
},
|
|
27
|
+
]);
|
|
22
28
|
}
|
|
23
29
|
}
|
|
24
30
|
return await method.apply(context, args);
|
package/src/utils/query.ts
CHANGED
|
@@ -546,93 +546,6 @@ export const calculateBorrowIncentivePoolPointData = (
|
|
|
546
546
|
};
|
|
547
547
|
};
|
|
548
548
|
|
|
549
|
-
// /**
|
|
550
|
-
// * Parse origin borrow incentive reward pool data to a more readable format.
|
|
551
|
-
// *
|
|
552
|
-
// * @param originBorrowIncentiveRewardPoolData - Origin borrow incentive reward pool data
|
|
553
|
-
// * @return Parsed borrow incentive reward pool data
|
|
554
|
-
// */
|
|
555
|
-
// export const parseOriginBorrowIncentiveRewardPoolData = (
|
|
556
|
-
// originBorrowIncentiveRewardPoolData: OriginBorrowIncentiveRewardPoolData
|
|
557
|
-
// ): ParsedBorrowIncentiveRewardPoolData => {
|
|
558
|
-
// return {
|
|
559
|
-
// rewardType: normalizeStructTag(
|
|
560
|
-
// originBorrowIncentiveRewardPoolData.reward_type.name
|
|
561
|
-
// ),
|
|
562
|
-
// claimedRewards: Number(originBorrowIncentiveRewardPoolData.claimed_rewards),
|
|
563
|
-
// exchangeRateNumerator: Number(
|
|
564
|
-
// originBorrowIncentiveRewardPoolData.exchange_rate_numerator
|
|
565
|
-
// ),
|
|
566
|
-
// exchangeRateDenominator: Number(
|
|
567
|
-
// originBorrowIncentiveRewardPoolData.exchange_rate_denominator
|
|
568
|
-
// ),
|
|
569
|
-
// remainingRewards: Number(
|
|
570
|
-
// originBorrowIncentiveRewardPoolData.remaining_reward
|
|
571
|
-
// ),
|
|
572
|
-
// };
|
|
573
|
-
// };
|
|
574
|
-
|
|
575
|
-
// export const calculateBorrowIncentiveRewardPoolData = (
|
|
576
|
-
// parsedBorrowIncentivePoolData: ParsedBorrowIncentivePoolData,
|
|
577
|
-
// parsedBorrowIncentiveRewardPoolData: ParsedBorrowIncentiveRewardPoolData,
|
|
578
|
-
// calculatedBorrowIncentivePoolData: CalculatedBorrowIncentivePoolData,
|
|
579
|
-
// rewardCoinPrice: number,
|
|
580
|
-
// rewardCoinDecimal: number
|
|
581
|
-
// ): CalculatedBorrowIncentiveRewardPoolData => {
|
|
582
|
-
// const rateYearFactor = 365 * 24 * 60 * 60;
|
|
583
|
-
|
|
584
|
-
// const rewardPerSec = BigNumber(
|
|
585
|
-
// calculatedBorrowIncentivePoolData.distributedPointPerSec
|
|
586
|
-
// )
|
|
587
|
-
// .multipliedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateNumerator)
|
|
588
|
-
// .dividedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateDenominator);
|
|
589
|
-
// const totalRewardAmount = BigNumber(parsedBorrowIncentivePoolData.maxPoint)
|
|
590
|
-
// .multipliedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateNumerator)
|
|
591
|
-
// .dividedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateDenominator);
|
|
592
|
-
// const totalRewardCoin = totalRewardAmount.shiftedBy(-1 * rewardCoinDecimal);
|
|
593
|
-
// const totalRewardValue = totalRewardCoin.multipliedBy(rewardCoinPrice);
|
|
594
|
-
// const remaindRewardAmount = BigNumber(
|
|
595
|
-
// parsedBorrowIncentiveRewardPoolData.remainingRewards
|
|
596
|
-
// );
|
|
597
|
-
// const remaindRewardCoin = remaindRewardAmount.shiftedBy(
|
|
598
|
-
// -1 * rewardCoinDecimal
|
|
599
|
-
// );
|
|
600
|
-
// const remaindRewardValue = remaindRewardCoin.multipliedBy(rewardCoinPrice);
|
|
601
|
-
// const claimedRewardAmount = BigNumber(
|
|
602
|
-
// parsedBorrowIncentiveRewardPoolData.claimedRewards
|
|
603
|
-
// );
|
|
604
|
-
// const claimedRewardCoin = claimedRewardAmount.shiftedBy(
|
|
605
|
-
// -1 * rewardCoinDecimal
|
|
606
|
-
// );
|
|
607
|
-
// const claimedRewardValue = claimedRewardCoin.multipliedBy(rewardCoinPrice);
|
|
608
|
-
|
|
609
|
-
// const rewardValueForYear = BigNumber(rewardPerSec)
|
|
610
|
-
// .shiftedBy(-1 * rewardCoinDecimal)
|
|
611
|
-
// .multipliedBy(rateYearFactor)
|
|
612
|
-
// .multipliedBy(rewardCoinPrice);
|
|
613
|
-
// const rewardRate = rewardValueForYear
|
|
614
|
-
// .dividedBy(calculatedBorrowIncentivePoolData.stakedValue)
|
|
615
|
-
// .isFinite()
|
|
616
|
-
// ? rewardValueForYear
|
|
617
|
-
// .dividedBy(calculatedBorrowIncentivePoolData.stakedValue)
|
|
618
|
-
// .toNumber()
|
|
619
|
-
// : Infinity;
|
|
620
|
-
|
|
621
|
-
// return {
|
|
622
|
-
// rewardApr: rewardRate,
|
|
623
|
-
// totalRewardAmount: totalRewardAmount.toNumber(),
|
|
624
|
-
// totalRewardCoin: totalRewardCoin.toNumber(),
|
|
625
|
-
// totalRewardValue: totalRewardValue.toNumber(),
|
|
626
|
-
// remaindRewardAmount: remaindRewardAmount.toNumber(),
|
|
627
|
-
// remaindRewardCoin: remaindRewardCoin.toNumber(),
|
|
628
|
-
// remaindRewardValue: remaindRewardValue.toNumber(),
|
|
629
|
-
// claimedRewardAmount: claimedRewardAmount.toNumber(),
|
|
630
|
-
// claimedRewardCoin: claimedRewardCoin.toNumber(),
|
|
631
|
-
// claimedRewardValue: claimedRewardValue.toNumber(),
|
|
632
|
-
// rewardPerSec: rewardPerSec.toNumber(),
|
|
633
|
-
// };
|
|
634
|
-
// };
|
|
635
|
-
|
|
636
549
|
export const parseOriginBorrowIncentiveAccountPoolPointData = (
|
|
637
550
|
originBorrowIncentiveAccountPoolPointData: OriginBorrowIncentiveAccountPoolData
|
|
638
551
|
): ParsedBorrowIncentiveAccountPoolData => {
|
package/src/utils/tokenBucket.ts
CHANGED
|
@@ -38,8 +38,8 @@ const callWithRateLimit = async <T>(
|
|
|
38
38
|
tokenBucket: TokenBucket,
|
|
39
39
|
fn: () => Promise<T>,
|
|
40
40
|
retryDelayInMs = DEFAULT_INTERVAL_IN_MS,
|
|
41
|
-
maxRetries =
|
|
42
|
-
backoffFactor =
|
|
41
|
+
maxRetries = 15,
|
|
42
|
+
backoffFactor = 2 // The factor by which to increase the delay
|
|
43
43
|
): Promise<T | null> => {
|
|
44
44
|
let retries = 0;
|
|
45
45
|
|