@scallop-io/sui-scallop-sdk 0.44.6 → 0.44.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.
- package/README.md +8 -1
- package/dist/constants/common.d.ts +2 -1
- package/dist/index.js +488 -92
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +486 -92
- package/dist/index.mjs.map +1 -1
- package/dist/models/index.d.ts +1 -0
- package/dist/models/scallop.d.ts +9 -1
- package/dist/models/scallopAddress.d.ts +1 -1
- package/dist/models/scallopBuilder.d.ts +1 -1
- package/dist/models/scallopClient.d.ts +1 -1
- package/dist/models/scallopIndexer.d.ts +81 -0
- package/dist/models/scallopQuery.d.ts +31 -15
- package/dist/queries/borrowIncentiveQuery.d.ts +4 -1
- package/dist/queries/coreQuery.d.ts +10 -6
- package/dist/queries/portfolioQuery.d.ts +10 -5
- package/dist/queries/spoolQuery.d.ts +6 -3
- package/dist/types/query/portfolio.d.ts +2 -0
- package/dist/utils/query.d.ts +8 -0
- package/package.json +1 -1
- package/src/constants/common.ts +2 -1
- package/src/constants/enum.ts +1 -0
- package/src/models/index.ts +1 -0
- package/src/models/scallop.ts +14 -1
- package/src/models/scallopAddress.ts +1 -1
- package/src/models/scallopBuilder.ts +1 -1
- package/src/models/scallopClient.ts +36 -1
- package/src/models/scallopIndexer.ts +269 -0
- package/src/models/scallopQuery.ts +71 -28
- package/src/queries/borrowIncentiveQuery.ts +27 -6
- package/src/queries/coreQuery.ts +104 -18
- package/src/queries/portfolioQuery.ts +111 -52
- package/src/queries/spoolQuery.ts +67 -9
- package/src/types/query/portfolio.ts +2 -0
- package/src/utils/query.ts +26 -0
|
@@ -18,6 +18,7 @@ import type {
|
|
|
18
18
|
StakeAccounts,
|
|
19
19
|
SupportStakeMarketCoins,
|
|
20
20
|
SupportStakeCoins,
|
|
21
|
+
CoinPrices,
|
|
21
22
|
} from '../types';
|
|
22
23
|
|
|
23
24
|
/**
|
|
@@ -25,25 +26,62 @@ import type {
|
|
|
25
26
|
*
|
|
26
27
|
* @param query - The Scallop query instance.
|
|
27
28
|
* @param marketCoinNames - Specific an array of support stake market coin name.
|
|
29
|
+
* @param indexer - Whether to use indexer.
|
|
28
30
|
* @return Spools data.
|
|
29
31
|
*/
|
|
30
32
|
export const getSpools = async (
|
|
31
33
|
query: ScallopQuery,
|
|
32
|
-
stakeMarketCoinNames?: SupportStakeMarketCoins[]
|
|
34
|
+
stakeMarketCoinNames?: SupportStakeMarketCoins[],
|
|
35
|
+
indexer: boolean = false
|
|
33
36
|
) => {
|
|
34
37
|
stakeMarketCoinNames = stakeMarketCoinNames || [...SUPPORT_SPOOLS];
|
|
35
38
|
const stakeCoinNames = stakeMarketCoinNames.map((stakeMarketCoinName) =>
|
|
36
39
|
query.utils.parseCoinName<SupportStakeCoins>(stakeMarketCoinName)
|
|
37
40
|
);
|
|
38
|
-
const
|
|
41
|
+
const rewardCoinNames = stakeMarketCoinNames.map((stakeMarketCoinName) => {
|
|
42
|
+
const rewardCoinName =
|
|
43
|
+
query.utils.getSpoolRewardCoinName(stakeMarketCoinName);
|
|
44
|
+
return rewardCoinName;
|
|
45
|
+
});
|
|
46
|
+
const coinPrices = await query.utils.getCoinPrices(
|
|
47
|
+
[...new Set([...stakeCoinNames, ...rewardCoinNames])] ?? []
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const marketPools = await query.getMarketPools(stakeCoinNames, indexer);
|
|
39
51
|
const spools: Spools = {};
|
|
52
|
+
|
|
53
|
+
if (indexer) {
|
|
54
|
+
const spoolsIndexer = await query.indexer.getSpools();
|
|
55
|
+
for (const spool of Object.values(spoolsIndexer)) {
|
|
56
|
+
if (!stakeMarketCoinNames.includes(spool.marketCoinName)) continue;
|
|
57
|
+
const coinName = query.utils.parseCoinName<SupportStakeCoins>(
|
|
58
|
+
spool.marketCoinName
|
|
59
|
+
);
|
|
60
|
+
const rewardCoinName = query.utils.getSpoolRewardCoinName(
|
|
61
|
+
spool.marketCoinName
|
|
62
|
+
);
|
|
63
|
+
const marketPool = marketPools[coinName];
|
|
64
|
+
spool.coinPrice = coinPrices[coinName] || spool.coinPrice;
|
|
65
|
+
spool.marketCoinPrice =
|
|
66
|
+
(coinPrices[coinName] ?? 0) *
|
|
67
|
+
(marketPool ? marketPool.conversionRate : 0) || spool.marketCoinPrice;
|
|
68
|
+
spool.rewardCoinPrice =
|
|
69
|
+
coinPrices[rewardCoinName] || spool.rewardCoinPrice;
|
|
70
|
+
spools[spool.marketCoinName] = spool;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return spools;
|
|
74
|
+
}
|
|
75
|
+
|
|
40
76
|
for (const stakeMarketCoinName of stakeMarketCoinNames) {
|
|
41
77
|
const stakeCoinName =
|
|
42
78
|
query.utils.parseCoinName<SupportStakeCoins>(stakeMarketCoinName);
|
|
43
79
|
const spool = await getSpool(
|
|
44
80
|
query,
|
|
45
81
|
stakeMarketCoinName,
|
|
46
|
-
|
|
82
|
+
indexer,
|
|
83
|
+
marketPools[stakeCoinName],
|
|
84
|
+
coinPrices
|
|
47
85
|
);
|
|
48
86
|
|
|
49
87
|
if (spool) {
|
|
@@ -59,22 +97,43 @@ export const getSpools = async (
|
|
|
59
97
|
*
|
|
60
98
|
* @param query - The Scallop query instance.
|
|
61
99
|
* @param marketCoinName - Specific support stake market coin name.
|
|
100
|
+
* @param indexer - Whether to use indexer.
|
|
62
101
|
* @param marketPool - The market pool data.
|
|
102
|
+
* @param coinPrices - The coin prices.
|
|
63
103
|
* @return Spool data.
|
|
64
104
|
*/
|
|
65
105
|
export const getSpool = async (
|
|
66
106
|
query: ScallopQuery,
|
|
67
107
|
marketCoinName: SupportStakeMarketCoins,
|
|
68
|
-
|
|
108
|
+
indexer: boolean = false,
|
|
109
|
+
marketPool?: MarketPool,
|
|
110
|
+
coinPrices?: CoinPrices
|
|
69
111
|
) => {
|
|
70
112
|
const coinName = query.utils.parseCoinName<SupportStakeCoins>(marketCoinName);
|
|
71
|
-
marketPool = marketPool || (await query.getMarketPool(coinName));
|
|
113
|
+
marketPool = marketPool || (await query.getMarketPool(coinName, indexer));
|
|
72
114
|
const spoolPkgId = query.address.get(`spool.id`);
|
|
73
115
|
const poolId = query.address.get(`spool.pools.${marketCoinName}.id`);
|
|
74
116
|
const rewardPoolId = query.address.get(
|
|
75
117
|
`spool.pools.${marketCoinName}.rewardPoolId`
|
|
76
118
|
);
|
|
77
119
|
let spool: Spool | undefined = undefined;
|
|
120
|
+
|
|
121
|
+
if (indexer) {
|
|
122
|
+
const spoolIndexer = await query.indexer.getSpool(marketCoinName);
|
|
123
|
+
const coinName =
|
|
124
|
+
query.utils.parseCoinName<SupportStakeCoins>(marketCoinName);
|
|
125
|
+
const rewardCoinName = query.utils.getSpoolRewardCoinName(marketCoinName);
|
|
126
|
+
spoolIndexer.coinPrice = coinPrices?.[coinName] || spoolIndexer.coinPrice;
|
|
127
|
+
spoolIndexer.marketCoinPrice =
|
|
128
|
+
(coinPrices?.[coinName] ?? 0) *
|
|
129
|
+
(marketPool ? marketPool.conversionRate : 0) ||
|
|
130
|
+
spoolIndexer.marketCoinPrice;
|
|
131
|
+
spoolIndexer.rewardCoinPrice =
|
|
132
|
+
coinPrices?.[rewardCoinName] || spoolIndexer.rewardCoinPrice;
|
|
133
|
+
|
|
134
|
+
return spoolIndexer;
|
|
135
|
+
}
|
|
136
|
+
|
|
78
137
|
const spoolObjectResponse = await query.suiKit.client().multiGetObjects({
|
|
79
138
|
ids: [poolId, rewardPoolId],
|
|
80
139
|
options: {
|
|
@@ -97,10 +156,9 @@ export const getSpool = async (
|
|
|
97
156
|
spoolObjectResponse[1].data
|
|
98
157
|
) {
|
|
99
158
|
const rewardCoinName = query.utils.getSpoolRewardCoinName(marketCoinName);
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
rewardCoinName
|
|
103
|
-
]);
|
|
159
|
+
coinPrices =
|
|
160
|
+
coinPrices ||
|
|
161
|
+
(await query.utils.getCoinPrices([coinName, rewardCoinName]));
|
|
104
162
|
|
|
105
163
|
const spoolObject = spoolObjectResponse[0].data;
|
|
106
164
|
const rewardPoolObject = spoolObjectResponse[1].data;
|
|
@@ -99,6 +99,8 @@ export type ObligationDebt = {
|
|
|
99
99
|
borrowedValue: number;
|
|
100
100
|
borrowedValueWithWeight: number;
|
|
101
101
|
borrowIndex: number;
|
|
102
|
+
requiredRepayAmount: number;
|
|
103
|
+
requiredRepayCoin: number;
|
|
102
104
|
availableBorrowAmount: number;
|
|
103
105
|
availableBorrowCoin: number;
|
|
104
106
|
availableRepayAmount: number;
|
package/src/utils/query.ts
CHANGED
|
@@ -612,3 +612,29 @@ export const maxBigNumber = (...args: BigNumber.Value[]) => {
|
|
|
612
612
|
)
|
|
613
613
|
);
|
|
614
614
|
};
|
|
615
|
+
|
|
616
|
+
/**
|
|
617
|
+
* Dynamically adjust the decrease or increase ratio according to the amout
|
|
618
|
+
* @param amount - The amount required to calculate factor.
|
|
619
|
+
* @param scaleStep - The scale step required to determine the factor..
|
|
620
|
+
* @param type - The type of the calculation.
|
|
621
|
+
* @return The estimated factor
|
|
622
|
+
* */
|
|
623
|
+
export const estimatedFactor = (
|
|
624
|
+
amount: number,
|
|
625
|
+
scaleStep: number,
|
|
626
|
+
type: 'increase' | 'decrease'
|
|
627
|
+
) => {
|
|
628
|
+
const amountOfDigits = Math.max(
|
|
629
|
+
1,
|
|
630
|
+
Math.floor(Math.log10(Math.abs(amount)) + 1)
|
|
631
|
+
);
|
|
632
|
+
|
|
633
|
+
const adjustScale =
|
|
634
|
+
Math.max(Math.floor((amountOfDigits - 1) / scaleStep), 1) + 1;
|
|
635
|
+
|
|
636
|
+
let adjustFactor = Math.pow(10, -adjustScale);
|
|
637
|
+
adjustFactor = type === 'increase' ? 1 - adjustFactor : 1 + adjustFactor;
|
|
638
|
+
|
|
639
|
+
return adjustFactor;
|
|
640
|
+
};
|