@scallop-io/sui-scallop-sdk 1.4.1 → 1.4.2-rc.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 +1 -1
- package/dist/constants/poolAddress.d.ts +16 -4
- package/dist/constants/queryKeys.d.ts +2 -2
- package/dist/constants/tokenBucket.d.ts +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1270 -588
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1225 -544
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopBuilder.d.ts +2 -1
- package/dist/models/scallopCache.d.ts +2 -0
- package/dist/models/scallopQuery.d.ts +38 -20
- package/dist/models/scallopUtils.d.ts +4 -2
- package/dist/queries/borrowIncentiveQuery.d.ts +12 -0
- package/dist/queries/coreQuery.d.ts +18 -19
- package/dist/queries/index.d.ts +2 -0
- package/dist/queries/isolatedAssetQuery.d.ts +2 -2
- package/dist/queries/objectsQuery.d.ts +3 -0
- package/dist/queries/poolAddressesQuery.d.ts +18 -0
- package/dist/queries/spoolQuery.d.ts +6 -2
- package/dist/test.d.ts +1 -0
- package/dist/types/builder/borrowIncentive.d.ts +5 -5
- package/dist/types/builder/core.d.ts +20 -16
- package/dist/types/builder/loyaltyProgram.d.ts +1 -1
- package/dist/types/builder/referral.d.ts +4 -4
- package/dist/types/builder/sCoin.d.ts +2 -2
- package/dist/types/builder/spool.d.ts +4 -4
- package/dist/types/builder/vesca.d.ts +6 -6
- package/dist/types/query/core.d.ts +22 -5
- package/dist/types/query/spool.d.ts +20 -0
- package/dist/types/utils.d.ts +7 -2
- package/dist/utils/core.d.ts +2 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/query.d.ts +1 -1
- package/dist/utils/util.d.ts +1 -0
- package/package.json +7 -7
- package/src/builders/borrowIncentiveBuilder.ts +28 -15
- package/src/builders/coreBuilder.ts +76 -49
- package/src/builders/loyaltyProgramBuilder.ts +4 -3
- package/src/builders/referralBuilder.ts +23 -10
- package/src/builders/sCoinBuilder.ts +8 -6
- package/src/builders/spoolBuilder.ts +21 -14
- package/src/builders/vescaBuilder.ts +23 -13
- package/src/constants/common.ts +1 -12
- package/src/constants/poolAddress.ts +336 -10
- package/src/constants/queryKeys.ts +9 -5
- package/src/constants/testAddress.ts +42 -0
- package/src/constants/tokenBucket.ts +2 -2
- package/src/index.ts +1 -0
- package/src/models/scallopBuilder.ts +59 -2
- package/src/models/scallopCache.ts +171 -19
- package/src/models/scallopClient.ts +16 -10
- package/src/models/scallopQuery.ts +36 -28
- package/src/models/scallopUtils.ts +11 -4
- package/src/queries/borrowIncentiveQuery.ts +6 -8
- package/src/queries/borrowLimitQuery.ts +1 -0
- package/src/queries/coreQuery.ts +408 -258
- package/src/queries/index.ts +2 -0
- package/src/queries/isolatedAssetQuery.ts +37 -31
- package/src/queries/objectsQuery.ts +20 -0
- package/src/queries/poolAddressesQuery.ts +146 -0
- package/src/queries/portfolioQuery.ts +31 -13
- package/src/queries/priceQuery.ts +3 -1
- package/src/queries/spoolQuery.ts +189 -122
- package/src/test.ts +17 -0
- package/src/types/builder/borrowIncentive.ts +8 -5
- package/src/types/builder/core.ts +23 -17
- package/src/types/builder/loyaltyProgram.ts +1 -1
- package/src/types/builder/referral.ts +6 -4
- package/src/types/builder/sCoin.ts +2 -2
- package/src/types/builder/spool.ts +4 -4
- package/src/types/builder/vesca.ts +9 -6
- package/src/types/query/core.ts +21 -5
- package/src/types/query/spool.ts +21 -0
- package/src/types/utils.ts +8 -3
- package/src/utils/core.ts +18 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/query.ts +21 -5
- package/src/utils/tokenBucket.ts +9 -29
- package/src/utils/util.ts +8 -0
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { normalizeStructTag } from '@mysten/sui/utils';
|
|
2
|
-
import { SUPPORT_SPOOLS } from '../constants';
|
|
2
|
+
import { POOL_ADDRESSES, SUPPORT_SPOOLS } from '../constants';
|
|
3
3
|
import {
|
|
4
4
|
parseOriginSpoolData,
|
|
5
5
|
calculateSpoolData,
|
|
6
6
|
parseOriginSpoolRewardPoolData,
|
|
7
7
|
calculateSpoolRewardPoolData,
|
|
8
8
|
isMarketCoin,
|
|
9
|
+
parseObjectAs,
|
|
9
10
|
} from '../utils';
|
|
10
|
-
import type { SuiObjectResponse } from '@mysten/sui/client';
|
|
11
|
+
import type { SuiObjectData, SuiObjectResponse } from '@mysten/sui/client';
|
|
11
12
|
import type { ScallopQuery, ScallopUtils } from '../models';
|
|
12
13
|
import type {
|
|
13
|
-
MarketPool,
|
|
14
14
|
Spools,
|
|
15
15
|
Spool,
|
|
16
16
|
StakePool,
|
|
@@ -20,7 +20,107 @@ import type {
|
|
|
20
20
|
SupportStakeCoins,
|
|
21
21
|
CoinPrices,
|
|
22
22
|
MarketPools,
|
|
23
|
+
OriginSpoolRewardPoolData,
|
|
24
|
+
SpoolData,
|
|
25
|
+
OriginSpoolData,
|
|
23
26
|
} from '../types';
|
|
27
|
+
import { queryMultipleObjects } from './objectsQuery';
|
|
28
|
+
|
|
29
|
+
const queryRequiredSpoolObjects = async (
|
|
30
|
+
query: ScallopQuery,
|
|
31
|
+
stakePoolCoinNames: SupportStakeCoins[]
|
|
32
|
+
) => {
|
|
33
|
+
// Prepare all tasks for querying each object type
|
|
34
|
+
const tasks = stakePoolCoinNames.map((t, idx) => ({
|
|
35
|
+
poolCoinName: stakePoolCoinNames[idx],
|
|
36
|
+
spool: POOL_ADDRESSES[t]?.spool,
|
|
37
|
+
spoolReward: POOL_ADDRESSES[t]?.spoolReward,
|
|
38
|
+
sCoinTreasury: POOL_ADDRESSES[t]?.sCoinTreasury,
|
|
39
|
+
}));
|
|
40
|
+
|
|
41
|
+
// Query all objects for each key in parallel
|
|
42
|
+
const [spoolObjects, spoolRewardObjects, sCoinTreasuryObjects] =
|
|
43
|
+
await Promise.all([
|
|
44
|
+
queryMultipleObjects(
|
|
45
|
+
query.cache,
|
|
46
|
+
tasks.map((task) => task.spool).filter((t): t is string => !!t)
|
|
47
|
+
),
|
|
48
|
+
queryMultipleObjects(
|
|
49
|
+
query.cache,
|
|
50
|
+
tasks.map((task) => task.spoolReward).filter((t): t is string => !!t)
|
|
51
|
+
),
|
|
52
|
+
queryMultipleObjects(
|
|
53
|
+
query.cache,
|
|
54
|
+
tasks.map((task) => task.sCoinTreasury).filter((t): t is string => !!t)
|
|
55
|
+
),
|
|
56
|
+
]);
|
|
57
|
+
|
|
58
|
+
// Map the results back to poolCoinNames
|
|
59
|
+
const mapObjects = (
|
|
60
|
+
tasks: { poolCoinName: string; [key: string]: string | undefined }[],
|
|
61
|
+
fetchedObjects: SuiObjectData[]
|
|
62
|
+
) => {
|
|
63
|
+
const resultMap: Record<string, SuiObjectData> = {};
|
|
64
|
+
let fetchedIndex = 0;
|
|
65
|
+
|
|
66
|
+
for (const task of tasks) {
|
|
67
|
+
const key = task[Object.keys(task)[1]]; // current object key being queried
|
|
68
|
+
if (key) {
|
|
69
|
+
resultMap[task.poolCoinName] = fetchedObjects[fetchedIndex];
|
|
70
|
+
fetchedIndex++;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return resultMap;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const spoolMap = mapObjects(tasks, spoolObjects);
|
|
77
|
+
const spoolRewardMap = mapObjects(tasks, spoolRewardObjects);
|
|
78
|
+
const sCoinTreasuryMap = mapObjects(tasks, sCoinTreasuryObjects);
|
|
79
|
+
|
|
80
|
+
// Construct the final requiredObjects result
|
|
81
|
+
return stakePoolCoinNames.reduce(
|
|
82
|
+
(acc, name) => {
|
|
83
|
+
acc[name] = {
|
|
84
|
+
spool: spoolMap[name],
|
|
85
|
+
spoolReward: spoolRewardMap[name],
|
|
86
|
+
sCoinTreasury: sCoinTreasuryMap[name],
|
|
87
|
+
};
|
|
88
|
+
return acc;
|
|
89
|
+
},
|
|
90
|
+
{} as Record<
|
|
91
|
+
SupportStakeCoins,
|
|
92
|
+
{
|
|
93
|
+
spool: SuiObjectData;
|
|
94
|
+
spoolReward: SuiObjectData;
|
|
95
|
+
sCoinTreasury: SuiObjectData;
|
|
96
|
+
}
|
|
97
|
+
>
|
|
98
|
+
);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const parseSpoolObjects = ({
|
|
102
|
+
spool,
|
|
103
|
+
spoolReward,
|
|
104
|
+
}: {
|
|
105
|
+
spool: SuiObjectData;
|
|
106
|
+
spoolReward: SuiObjectData;
|
|
107
|
+
}): OriginSpoolData & OriginSpoolRewardPoolData => {
|
|
108
|
+
const _spool = parseObjectAs<SpoolData>(spool);
|
|
109
|
+
const _spoolReward = parseObjectAs<OriginSpoolRewardPoolData>(spoolReward);
|
|
110
|
+
return {
|
|
111
|
+
stakeType: _spool.stake_type,
|
|
112
|
+
maxDistributedPoint: _spool.max_distributed_point,
|
|
113
|
+
distributedPoint: _spool.distributed_point,
|
|
114
|
+
distributedPointPerPeriod: _spool.distributed_point_per_period,
|
|
115
|
+
pointDistributionTime: _spool.point_distribution_time,
|
|
116
|
+
maxStake: _spool.max_stakes,
|
|
117
|
+
stakes: _spool.stakes,
|
|
118
|
+
index: _spool.index,
|
|
119
|
+
createdAt: _spool.created_at,
|
|
120
|
+
lastUpdate: _spool.last_update,
|
|
121
|
+
..._spoolReward,
|
|
122
|
+
};
|
|
123
|
+
};
|
|
24
124
|
|
|
25
125
|
/**
|
|
26
126
|
* Get spools data.
|
|
@@ -40,10 +140,13 @@ export const getSpools = async (
|
|
|
40
140
|
const stakeCoinNames = stakeMarketCoinNames.map((stakeMarketCoinName) =>
|
|
41
141
|
query.utils.parseCoinName<SupportStakeCoins>(stakeMarketCoinName)
|
|
42
142
|
);
|
|
43
|
-
coinPrices = coinPrices ?? (await query.utils.getCoinPrices()) ?? {};
|
|
44
|
-
|
|
45
143
|
marketPools =
|
|
46
|
-
marketPools ??
|
|
144
|
+
marketPools ??
|
|
145
|
+
(await query.getMarketPools(stakeCoinNames, { indexer })).pools;
|
|
146
|
+
|
|
147
|
+
coinPrices =
|
|
148
|
+
coinPrices ?? (await query.getAllCoinPrices({ marketPools })) ?? {};
|
|
149
|
+
|
|
47
150
|
if (!marketPools)
|
|
48
151
|
throw new Error(`Fail to fetch marketPools for ${stakeCoinNames}`);
|
|
49
152
|
|
|
@@ -59,12 +162,9 @@ export const getSpools = async (
|
|
|
59
162
|
const rewardCoinName = query.utils.getSpoolRewardCoinName(
|
|
60
163
|
spool.marketCoinName
|
|
61
164
|
);
|
|
62
|
-
const marketPool = marketPools[coinName];
|
|
63
165
|
spool.coinPrice = coinPrices[coinName] ?? spool.coinPrice;
|
|
64
|
-
spool.marketCoinPrice =
|
|
65
|
-
|
|
66
|
-
(marketPool ? marketPool.conversionRate : 0)
|
|
67
|
-
: spool.marketCoinPrice;
|
|
166
|
+
spool.marketCoinPrice =
|
|
167
|
+
coinPrices[spool.marketCoinName] ?? spool.marketCoinPrice;
|
|
68
168
|
spool.rewardCoinPrice =
|
|
69
169
|
coinPrices[rewardCoinName] ?? spool.rewardCoinPrice;
|
|
70
170
|
spools[spool.marketCoinName] = spool;
|
|
@@ -74,21 +174,31 @@ export const getSpools = async (
|
|
|
74
174
|
return spools;
|
|
75
175
|
}
|
|
76
176
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
query,
|
|
82
|
-
stakeMarketCoinName,
|
|
83
|
-
indexer,
|
|
84
|
-
marketPools[stakeCoinName],
|
|
85
|
-
coinPrices
|
|
86
|
-
);
|
|
177
|
+
const requiredObjects = await queryRequiredSpoolObjects(
|
|
178
|
+
query,
|
|
179
|
+
stakeCoinNames
|
|
180
|
+
);
|
|
87
181
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
182
|
+
await Promise.allSettled(
|
|
183
|
+
stakeMarketCoinNames.map(async (stakeMarketCoinName, idx) => {
|
|
184
|
+
try {
|
|
185
|
+
const stakeCoinName = stakeCoinNames[idx];
|
|
186
|
+
const spool = await getSpool(
|
|
187
|
+
query,
|
|
188
|
+
stakeMarketCoinName,
|
|
189
|
+
indexer,
|
|
190
|
+
coinPrices,
|
|
191
|
+
requiredObjects[stakeCoinName]
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
if (spool) {
|
|
195
|
+
spools[stakeMarketCoinName] = spool;
|
|
196
|
+
}
|
|
197
|
+
} catch (e) {
|
|
198
|
+
console.error(e);
|
|
199
|
+
}
|
|
200
|
+
})
|
|
201
|
+
);
|
|
92
202
|
|
|
93
203
|
return spools;
|
|
94
204
|
};
|
|
@@ -107,126 +217,83 @@ export const getSpool = async (
|
|
|
107
217
|
query: ScallopQuery,
|
|
108
218
|
marketCoinName: SupportStakeMarketCoins,
|
|
109
219
|
indexer: boolean = false,
|
|
110
|
-
|
|
111
|
-
|
|
220
|
+
coinPrices?: CoinPrices,
|
|
221
|
+
requiredObjects?: {
|
|
222
|
+
spool: SuiObjectData;
|
|
223
|
+
spoolReward: SuiObjectData;
|
|
224
|
+
}
|
|
112
225
|
) => {
|
|
113
226
|
const coinName = query.utils.parseCoinName<SupportStakeCoins>(marketCoinName);
|
|
114
|
-
|
|
115
|
-
if (!marketPool) {
|
|
116
|
-
throw new Error(`Failed to fetch marketPool for ${marketCoinName}`);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const poolId = query.address.get(`spool.pools.${marketCoinName}.id`);
|
|
120
|
-
const rewardPoolId = query.address.get(
|
|
121
|
-
`spool.pools.${marketCoinName}.rewardPoolId`
|
|
122
|
-
);
|
|
123
|
-
let spool: Spool | undefined = undefined;
|
|
124
|
-
coinPrices = coinPrices || (await query.utils.getCoinPrices());
|
|
227
|
+
coinPrices = coinPrices || (await query.getAllCoinPrices());
|
|
125
228
|
|
|
126
229
|
if (indexer) {
|
|
127
230
|
const spoolIndexer = await query.indexer.getSpool(marketCoinName);
|
|
128
231
|
const coinName =
|
|
129
232
|
query.utils.parseCoinName<SupportStakeCoins>(marketCoinName);
|
|
130
233
|
const rewardCoinName = query.utils.getSpoolRewardCoinName(marketCoinName);
|
|
131
|
-
spoolIndexer.coinPrice = coinPrices?.[coinName]
|
|
234
|
+
spoolIndexer.coinPrice = coinPrices?.[coinName] ?? spoolIndexer.coinPrice;
|
|
132
235
|
spoolIndexer.marketCoinPrice =
|
|
133
|
-
|
|
134
|
-
(marketPool ? marketPool.conversionRate : 0) ||
|
|
135
|
-
spoolIndexer.marketCoinPrice;
|
|
236
|
+
coinPrices?.[marketCoinName] ?? spoolIndexer.marketCoinPrice;
|
|
136
237
|
spoolIndexer.rewardCoinPrice =
|
|
137
|
-
coinPrices?.[rewardCoinName]
|
|
238
|
+
coinPrices?.[rewardCoinName] ?? spoolIndexer.rewardCoinPrice;
|
|
138
239
|
|
|
139
240
|
return spoolIndexer;
|
|
140
241
|
}
|
|
141
242
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
showContent: true,
|
|
146
|
-
}
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
if (!(spoolObjectResponse[0] && spoolObjectResponse[1])) {
|
|
150
|
-
throw new Error('Fail to fetch spoolObjectResponse!');
|
|
151
|
-
}
|
|
243
|
+
requiredObjects ??= (await queryRequiredSpoolObjects(query, [coinName]))[
|
|
244
|
+
coinName
|
|
245
|
+
];
|
|
152
246
|
|
|
153
247
|
const rewardCoinName = query.utils.getSpoolRewardCoinName(marketCoinName);
|
|
154
248
|
coinPrices = coinPrices || (await query.utils.getCoinPrices());
|
|
155
249
|
|
|
156
|
-
const
|
|
157
|
-
const
|
|
158
|
-
if (spoolObject.content && 'fields' in spoolObject.content) {
|
|
159
|
-
const spoolFields = spoolObject.content.fields as any;
|
|
160
|
-
const parsedSpoolData = parseOriginSpoolData({
|
|
161
|
-
stakeType: spoolFields.stake_type,
|
|
162
|
-
maxDistributedPoint: spoolFields.max_distributed_point,
|
|
163
|
-
distributedPoint: spoolFields.distributed_point,
|
|
164
|
-
distributedPointPerPeriod: spoolFields.distributed_point_per_period,
|
|
165
|
-
pointDistributionTime: spoolFields.point_distribution_time,
|
|
166
|
-
maxStake: spoolFields.max_stakes,
|
|
167
|
-
stakes: spoolFields.stakes,
|
|
168
|
-
index: spoolFields.index,
|
|
169
|
-
createdAt: spoolFields.created_at,
|
|
170
|
-
lastUpdate: spoolFields.last_update,
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
const marketCoinPrice =
|
|
174
|
-
(coinPrices?.[coinName] ?? 0) * marketPool.conversionRate;
|
|
175
|
-
const marketCoinDecimal = query.utils.getCoinDecimal(marketCoinName);
|
|
176
|
-
const calculatedSpoolData = calculateSpoolData(
|
|
177
|
-
parsedSpoolData,
|
|
178
|
-
marketCoinPrice,
|
|
179
|
-
marketCoinDecimal
|
|
180
|
-
);
|
|
250
|
+
const parsedSpoolObjects = parseSpoolObjects(requiredObjects);
|
|
251
|
+
const parsedSpoolData = parseOriginSpoolData(parsedSpoolObjects);
|
|
181
252
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
spool_id: rewardPoolFields.spool_id,
|
|
190
|
-
});
|
|
253
|
+
const marketCoinPrice = coinPrices?.[marketCoinName] ?? 0;
|
|
254
|
+
const marketCoinDecimal = query.utils.getCoinDecimal(marketCoinName);
|
|
255
|
+
const calculatedSpoolData = calculateSpoolData(
|
|
256
|
+
parsedSpoolData,
|
|
257
|
+
marketCoinPrice,
|
|
258
|
+
marketCoinDecimal
|
|
259
|
+
);
|
|
191
260
|
|
|
192
|
-
|
|
193
|
-
|
|
261
|
+
const parsedSpoolRewardPoolData =
|
|
262
|
+
parseOriginSpoolRewardPoolData(parsedSpoolObjects);
|
|
194
263
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
parsedSpoolRewardPoolData,
|
|
198
|
-
calculatedSpoolData,
|
|
199
|
-
rewardCoinPrice,
|
|
200
|
-
rewardCoinDecimal
|
|
201
|
-
);
|
|
264
|
+
const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
|
|
265
|
+
const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
202
266
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
: query.utils.parseCoinType(rewardCoinName),
|
|
211
|
-
sCoinType: marketPool.sCoinType,
|
|
212
|
-
coinDecimal: query.utils.getCoinDecimal(coinName),
|
|
213
|
-
rewardCoinDecimal: query.utils.getCoinDecimal(rewardCoinName),
|
|
214
|
-
coinPrice: coinPrices?.[coinName] ?? 0,
|
|
215
|
-
marketCoinPrice: marketCoinPrice,
|
|
216
|
-
rewardCoinPrice: rewardCoinPrice,
|
|
217
|
-
maxPoint: parsedSpoolData.maxPoint,
|
|
218
|
-
distributedPoint: parsedSpoolData.distributedPoint,
|
|
219
|
-
maxStake: parsedSpoolData.maxStake,
|
|
220
|
-
...calculatedSpoolData,
|
|
221
|
-
exchangeRateNumerator: parsedSpoolRewardPoolData.exchangeRateNumerator,
|
|
222
|
-
exchangeRateDenominator:
|
|
223
|
-
parsedSpoolRewardPoolData.exchangeRateDenominator,
|
|
224
|
-
...calculatedRewardPoolData,
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
}
|
|
267
|
+
const calculatedRewardPoolData = calculateSpoolRewardPoolData(
|
|
268
|
+
parsedSpoolData,
|
|
269
|
+
parsedSpoolRewardPoolData,
|
|
270
|
+
calculatedSpoolData,
|
|
271
|
+
rewardCoinPrice,
|
|
272
|
+
rewardCoinDecimal
|
|
273
|
+
);
|
|
228
274
|
|
|
229
|
-
return
|
|
275
|
+
return {
|
|
276
|
+
marketCoinName: marketCoinName,
|
|
277
|
+
symbol: query.utils.parseSymbol(marketCoinName),
|
|
278
|
+
coinType: query.utils.parseCoinType(coinName),
|
|
279
|
+
marketCoinType: query.utils.parseMarketCoinType(coinName),
|
|
280
|
+
rewardCoinType: isMarketCoin(rewardCoinName)
|
|
281
|
+
? query.utils.parseMarketCoinType(rewardCoinName)
|
|
282
|
+
: query.utils.parseCoinType(rewardCoinName),
|
|
283
|
+
sCoinType: query.utils.parseSCoinType(marketCoinName),
|
|
284
|
+
coinDecimal: query.utils.getCoinDecimal(coinName),
|
|
285
|
+
rewardCoinDecimal: query.utils.getCoinDecimal(rewardCoinName),
|
|
286
|
+
coinPrice: coinPrices?.[coinName] ?? 0,
|
|
287
|
+
marketCoinPrice: marketCoinPrice,
|
|
288
|
+
rewardCoinPrice: rewardCoinPrice,
|
|
289
|
+
maxPoint: parsedSpoolData.maxPoint,
|
|
290
|
+
distributedPoint: parsedSpoolData.distributedPoint,
|
|
291
|
+
maxStake: parsedSpoolData.maxStake,
|
|
292
|
+
...calculatedSpoolData,
|
|
293
|
+
exchangeRateNumerator: parsedSpoolRewardPoolData.exchangeRateNumerator,
|
|
294
|
+
exchangeRateDenominator: parsedSpoolRewardPoolData.exchangeRateDenominator,
|
|
295
|
+
...calculatedRewardPoolData,
|
|
296
|
+
};
|
|
230
297
|
};
|
|
231
298
|
|
|
232
299
|
/**
|
package/src/test.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ScallopQuery } from './models';
|
|
2
|
+
|
|
3
|
+
const main = async () => {
|
|
4
|
+
try {
|
|
5
|
+
const query = new ScallopQuery({});
|
|
6
|
+
await query.init();
|
|
7
|
+
|
|
8
|
+
const res = await query.getSpool('ssui');
|
|
9
|
+
console.dir(res, { depth: null });
|
|
10
|
+
} catch (e) {
|
|
11
|
+
console.error(e);
|
|
12
|
+
} finally {
|
|
13
|
+
process.exit(0);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
main();
|
|
@@ -19,22 +19,25 @@ export type BorrowIncentiveNormalMethods = {
|
|
|
19
19
|
stakeObligation: (
|
|
20
20
|
obligation: SuiObjectArg,
|
|
21
21
|
obligationKey: SuiObjectArg
|
|
22
|
-
) => void
|
|
22
|
+
) => Promise<void>;
|
|
23
23
|
stakeObligationWithVesca: (
|
|
24
24
|
obligation: SuiObjectArg,
|
|
25
25
|
obligationKey: SuiObjectArg,
|
|
26
26
|
veScaKey: SuiObjectArg
|
|
27
|
-
) => void
|
|
27
|
+
) => Promise<void>;
|
|
28
28
|
unstakeObligation: (
|
|
29
29
|
obligation: SuiObjectArg,
|
|
30
30
|
obligationKey: SuiObjectArg
|
|
31
|
-
) => void
|
|
31
|
+
) => Promise<void>;
|
|
32
32
|
claimBorrowIncentive: (
|
|
33
33
|
obligation: SuiObjectArg,
|
|
34
34
|
obligationKey: SuiObjectArg,
|
|
35
35
|
rewardType: SupportBorrowIncentiveRewardCoins
|
|
36
|
-
) => TransactionResult
|
|
37
|
-
deactivateBoost: (
|
|
36
|
+
) => Promise<TransactionResult>;
|
|
37
|
+
deactivateBoost: (
|
|
38
|
+
obligation: SuiObjectArg,
|
|
39
|
+
veScaKey: SuiObjectArg
|
|
40
|
+
) => Promise<void>;
|
|
38
41
|
};
|
|
39
42
|
|
|
40
43
|
export type BorrowIncentiveQuickMethods = {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
SuiTxBlock as SuiKitTxBlock,
|
|
3
3
|
SuiObjectArg,
|
|
4
|
+
SuiTxArg,
|
|
4
5
|
} from '@scallop-io/sui-kit';
|
|
5
6
|
import type { Argument, TransactionResult } from '@mysten/sui/transactions';
|
|
6
7
|
import type { ScallopBuilder } from '../../models';
|
|
@@ -25,69 +26,74 @@ type ObligationKey = NestedResult;
|
|
|
25
26
|
type ObligationHotPotato = NestedResult;
|
|
26
27
|
|
|
27
28
|
export type CoreNormalMethods = {
|
|
28
|
-
openObligation: () =>
|
|
29
|
+
openObligation: () => Promise<
|
|
30
|
+
[Obligation, ObligationKey, ObligationHotPotato]
|
|
31
|
+
>;
|
|
29
32
|
returnObligation: (
|
|
30
33
|
obligation: SuiObjectArg,
|
|
31
34
|
obligationHotPotato: SuiObjectArg
|
|
32
|
-
) => void
|
|
33
|
-
openObligationEntry: () => void
|
|
35
|
+
) => Promise<void>;
|
|
36
|
+
openObligationEntry: () => Promise<void>;
|
|
34
37
|
addCollateral: (
|
|
35
38
|
obligation: SuiObjectArg,
|
|
36
39
|
coin: SuiObjectArg,
|
|
37
40
|
collateralCoinName: SupportCollateralCoins
|
|
38
|
-
) => void
|
|
41
|
+
) => Promise<void>;
|
|
39
42
|
takeCollateral: (
|
|
40
43
|
obligation: SuiObjectArg,
|
|
41
44
|
obligationKey: SuiObjectArg,
|
|
42
45
|
amount: number,
|
|
43
46
|
collateralCoinName: SupportCollateralCoins
|
|
44
|
-
) => TransactionResult
|
|
47
|
+
) => Promise<TransactionResult>;
|
|
45
48
|
deposit: (
|
|
46
49
|
coin: SuiObjectArg,
|
|
47
50
|
poolCoinName: SupportPoolCoins
|
|
48
|
-
) => TransactionResult
|
|
49
|
-
depositEntry: (
|
|
51
|
+
) => Promise<TransactionResult>;
|
|
52
|
+
depositEntry: (
|
|
53
|
+
coin: SuiObjectArg,
|
|
54
|
+
poolCoinName: SupportPoolCoins
|
|
55
|
+
) => Promise<TransactionResult>;
|
|
50
56
|
withdraw: (
|
|
51
57
|
marketCoin: SuiObjectArg,
|
|
52
58
|
poolCoinName: SupportPoolCoins
|
|
53
|
-
) => TransactionResult
|
|
59
|
+
) => Promise<TransactionResult>;
|
|
54
60
|
withdrawEntry: (
|
|
55
61
|
marketCoin: SuiObjectArg,
|
|
56
62
|
poolCoinName: SupportPoolCoins
|
|
57
|
-
) =>
|
|
63
|
+
) => Promise<TransactionResult>;
|
|
58
64
|
borrow: (
|
|
59
65
|
obligation: SuiObjectArg,
|
|
60
66
|
obligationKey: SuiObjectArg,
|
|
61
67
|
amount: number,
|
|
62
68
|
poolCoinName: SupportPoolCoins
|
|
63
|
-
) => TransactionResult
|
|
69
|
+
) => Promise<TransactionResult>;
|
|
64
70
|
borrowWithReferral: (
|
|
65
71
|
obligation: SuiObjectArg,
|
|
66
72
|
obligationKey: SuiObjectArg,
|
|
67
73
|
borrowReferral: SuiObjectArg,
|
|
68
|
-
amount: number,
|
|
74
|
+
amount: number | SuiTxArg,
|
|
69
75
|
poolCoinName: SupportPoolCoins
|
|
70
|
-
) => TransactionResult
|
|
76
|
+
) => Promise<TransactionResult>;
|
|
71
77
|
borrowEntry: (
|
|
72
78
|
obligation: SuiObjectArg,
|
|
73
79
|
obligationKey: SuiObjectArg,
|
|
74
80
|
amount: number,
|
|
75
81
|
poolCoinName: SupportPoolCoins
|
|
76
|
-
) =>
|
|
82
|
+
) => Promise<TransactionResult>;
|
|
77
83
|
repay: (
|
|
78
84
|
obligation: SuiObjectArg,
|
|
79
85
|
coin: SuiObjectArg,
|
|
80
86
|
poolCoinName: SupportPoolCoins
|
|
81
|
-
) => void
|
|
87
|
+
) => Promise<void>;
|
|
82
88
|
borrowFlashLoan: (
|
|
83
|
-
amount: number,
|
|
89
|
+
amount: number | SuiTxArg,
|
|
84
90
|
poolCoinName: SupportPoolCoins
|
|
85
|
-
) => TransactionResult
|
|
91
|
+
) => Promise<TransactionResult>;
|
|
86
92
|
repayFlashLoan: (
|
|
87
93
|
coin: SuiObjectArg,
|
|
88
94
|
loan: SuiObjectArg,
|
|
89
95
|
poolCoinName: SupportPoolCoins
|
|
90
|
-
) => void
|
|
96
|
+
) => Promise<void>;
|
|
91
97
|
};
|
|
92
98
|
|
|
93
99
|
export type CoreQuickMethods = {
|
|
@@ -12,7 +12,7 @@ export type LoyaltyProgramIds = {
|
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
export type LoyaltyProgramNormalMethods = {
|
|
15
|
-
claimLoyaltyRevenue: (veScaKey: SuiObjectArg) => TransactionResult
|
|
15
|
+
claimLoyaltyRevenue: (veScaKey: SuiObjectArg) => Promise<TransactionResult>;
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
export type LoyaltyProgramQuickMethods = {
|
|
@@ -16,16 +16,18 @@ export type ReferralIds = {
|
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
export type ReferralNormalMethods = {
|
|
19
|
-
bindToReferral: (veScaKeyId: string) => void
|
|
20
|
-
claimReferralTicket: (
|
|
19
|
+
bindToReferral: (veScaKeyId: string) => Promise<void>;
|
|
20
|
+
claimReferralTicket: (
|
|
21
|
+
poolCoinName: SupportPoolCoins
|
|
22
|
+
) => Promise<TransactionResult>;
|
|
21
23
|
burnReferralTicket: (
|
|
22
24
|
ticket: SuiObjectArg,
|
|
23
25
|
poolCoinName: SupportPoolCoins
|
|
24
|
-
) => void
|
|
26
|
+
) => Promise<void>;
|
|
25
27
|
claimReferralRevenue: (
|
|
26
28
|
veScaKey: SuiObjectArg,
|
|
27
29
|
poolCoinName: SupportPoolCoins
|
|
28
|
-
) => TransactionResult
|
|
30
|
+
) => Promise<TransactionResult>;
|
|
29
31
|
};
|
|
30
32
|
|
|
31
33
|
export type ReferralQuickMethods = {
|
|
@@ -21,7 +21,7 @@ export type sCoinNormalMethods = {
|
|
|
21
21
|
mintSCoin: (
|
|
22
22
|
marketCoinName: SupportSCoin,
|
|
23
23
|
marketCoin: SuiObjectArg
|
|
24
|
-
) => TransactionResult
|
|
24
|
+
) => Promise<TransactionResult>;
|
|
25
25
|
/**
|
|
26
26
|
* Burn sCoin and return marketCoin
|
|
27
27
|
* @param sCoinName
|
|
@@ -31,7 +31,7 @@ export type sCoinNormalMethods = {
|
|
|
31
31
|
burnSCoin: (
|
|
32
32
|
sCoinName: SupportSCoin,
|
|
33
33
|
sCoin: SuiObjectArg
|
|
34
|
-
) => TransactionResult
|
|
34
|
+
) => Promise<TransactionResult>; // returns marketCoin
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
export type sCoinQuickMethods = {
|
|
@@ -15,21 +15,21 @@ export type SpoolIds = {
|
|
|
15
15
|
export type SpoolNormalMethods = {
|
|
16
16
|
createStakeAccount: (
|
|
17
17
|
stakeMarketCoinName: SupportStakeMarketCoins
|
|
18
|
-
) => TransactionResult
|
|
18
|
+
) => Promise<TransactionResult>;
|
|
19
19
|
stake: (
|
|
20
20
|
stakeAccount: SuiAddressArg,
|
|
21
21
|
coin: SuiObjectArg,
|
|
22
22
|
stakeMarketCoinName: SupportStakeMarketCoins
|
|
23
|
-
) => void
|
|
23
|
+
) => Promise<void>;
|
|
24
24
|
unstake: (
|
|
25
25
|
stakeAccount: SuiAddressArg,
|
|
26
26
|
amount: number,
|
|
27
27
|
stakeMarketCoinName: SupportStakeMarketCoins
|
|
28
|
-
) => TransactionResult
|
|
28
|
+
) => Promise<TransactionResult>;
|
|
29
29
|
claim: (
|
|
30
30
|
stakeAccount: SuiAddressArg,
|
|
31
31
|
stakeMarketCoinName: SupportStakeMarketCoins
|
|
32
|
-
) => TransactionResult
|
|
32
|
+
) => Promise<TransactionResult>;
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
export type SpoolQuickMethods = {
|
|
@@ -13,19 +13,22 @@ export type VeScaNormalMethods = {
|
|
|
13
13
|
lockSca: (
|
|
14
14
|
scaCoin: SuiObjectArg,
|
|
15
15
|
unlockAtInSecondTimestamp: number
|
|
16
|
-
) => TransactionResult
|
|
16
|
+
) => Promise<TransactionResult>;
|
|
17
17
|
extendLockPeriod: (
|
|
18
18
|
veScaKey: SuiObjectArg,
|
|
19
19
|
newUnlockAtInSecondTimestamp: number
|
|
20
|
-
) => void
|
|
21
|
-
extendLockAmount: (
|
|
20
|
+
) => Promise<void>;
|
|
21
|
+
extendLockAmount: (
|
|
22
|
+
veScaKey: SuiObjectArg,
|
|
23
|
+
scaCoin: SuiObjectArg
|
|
24
|
+
) => Promise<void>;
|
|
22
25
|
renewExpiredVeSca: (
|
|
23
26
|
veScaKey: SuiObjectArg,
|
|
24
27
|
scaCoin: SuiObjectArg,
|
|
25
28
|
newUnlockAtInSecondTimestamp: number
|
|
26
|
-
) => void
|
|
27
|
-
redeemSca: (veScaKey: SuiObjectArg) => TransactionResult
|
|
28
|
-
mintEmptyVeSca: () => TransactionResult
|
|
29
|
+
) => Promise<void>;
|
|
30
|
+
redeemSca: (veScaKey: SuiObjectArg) => Promise<TransactionResult>;
|
|
31
|
+
mintEmptyVeSca: () => Promise<TransactionResult>;
|
|
29
32
|
};
|
|
30
33
|
|
|
31
34
|
export type RedeemScaQuickReturnType<T extends boolean> = T extends true
|