@scallop-io/sui-scallop-sdk 1.3.2-alpha.3 → 1.3.3-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/index.d.ts +1 -0
- package/dist/constants/queryKeys.d.ts +3 -5
- package/dist/index.js +830 -789
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1309 -1269
- package/dist/index.mjs.map +1 -1
- package/dist/types/query/core.d.ts +1 -0
- package/package.json +1 -2
- package/src/builders/spoolBuilder.ts +4 -0
- package/src/constants/enum.ts +8 -3
- package/src/constants/index.ts +1 -0
- package/src/constants/queryKeys.ts +3 -6
- package/src/constants/testAddress.ts +74 -33
- package/src/models/scallopBuilder.ts +2 -3
- package/src/models/scallopClient.ts +4 -4
- package/src/models/scallopQuery.ts +4 -3
- package/src/models/scallopUtils.ts +39 -26
- package/src/queries/coreQuery.ts +221 -213
- package/src/queries/isolatedAsset.ts +4 -4
- package/src/queries/referralQuery.ts +0 -1
- package/src/queries/sCoinQuery.ts +1 -1
- package/src/queries/spoolQuery.ts +76 -79
- package/src/queries/vescaQuery.ts +1 -1
- package/src/types/query/core.ts +1 -0
- package/dist/models/scallopPrice.d.ts +0 -0
- package/src/models/scallopPrice.ts +0 -0
|
@@ -113,6 +113,10 @@ export const getSpool = async (
|
|
|
113
113
|
) => {
|
|
114
114
|
const coinName = query.utils.parseCoinName<SupportStakeCoins>(marketCoinName);
|
|
115
115
|
marketPool = marketPool || (await query.getMarketPool(coinName, indexer));
|
|
116
|
+
if (!marketPool) {
|
|
117
|
+
throw new Error('Failed to fetch marketPool');
|
|
118
|
+
}
|
|
119
|
+
|
|
116
120
|
const poolId = query.address.get(`spool.pools.${marketCoinName}.id`);
|
|
117
121
|
const rewardPoolId = query.address.get(
|
|
118
122
|
`spool.pools.${marketCoinName}.rewardPoolId`
|
|
@@ -143,83 +147,83 @@ export const getSpool = async (
|
|
|
143
147
|
}
|
|
144
148
|
);
|
|
145
149
|
|
|
146
|
-
if (
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
150
|
+
if (!(spoolObjectResponse[0] && spoolObjectResponse[1])) {
|
|
151
|
+
throw new Error('Fail to fetch spoolObjectResponse!');
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const rewardCoinName = query.utils.getSpoolRewardCoinName(marketCoinName);
|
|
155
|
+
coinPrices =
|
|
156
|
+
coinPrices || (await query.utils.getCoinPrices([coinName, rewardCoinName]));
|
|
157
|
+
|
|
158
|
+
const spoolObject = spoolObjectResponse[0];
|
|
159
|
+
const rewardPoolObject = spoolObjectResponse[1];
|
|
160
|
+
if (spoolObject.content && 'fields' in spoolObject.content) {
|
|
161
|
+
const spoolFields = spoolObject.content.fields as any;
|
|
162
|
+
const parsedSpoolData = parseOriginSpoolData({
|
|
163
|
+
stakeType: spoolFields.stake_type,
|
|
164
|
+
maxDistributedPoint: spoolFields.max_distributed_point,
|
|
165
|
+
distributedPoint: spoolFields.distributed_point,
|
|
166
|
+
distributedPointPerPeriod: spoolFields.distributed_point_per_period,
|
|
167
|
+
pointDistributionTime: spoolFields.point_distribution_time,
|
|
168
|
+
maxStake: spoolFields.max_stakes,
|
|
169
|
+
stakes: spoolFields.stakes,
|
|
170
|
+
index: spoolFields.index,
|
|
171
|
+
createdAt: spoolFields.created_at,
|
|
172
|
+
lastUpdate: spoolFields.last_update,
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
const marketCoinPrice =
|
|
176
|
+
(coinPrices?.[coinName] ?? 0) * marketPool.conversionRate;
|
|
177
|
+
const marketCoinDecimal = query.utils.getCoinDecimal(marketCoinName);
|
|
178
|
+
const calculatedSpoolData = calculateSpoolData(
|
|
179
|
+
parsedSpoolData,
|
|
180
|
+
marketCoinPrice,
|
|
181
|
+
marketCoinDecimal
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
if (rewardPoolObject.content && 'fields' in rewardPoolObject.content) {
|
|
185
|
+
const rewardPoolFields = rewardPoolObject.content.fields as any;
|
|
186
|
+
const parsedSpoolRewardPoolData = parseOriginSpoolRewardPoolData({
|
|
187
|
+
claimed_rewards: rewardPoolFields.claimed_rewards,
|
|
188
|
+
exchange_rate_numerator: rewardPoolFields.exchange_rate_numerator,
|
|
189
|
+
exchange_rate_denominator: rewardPoolFields.exchange_rate_denominator,
|
|
190
|
+
rewards: rewardPoolFields.rewards,
|
|
191
|
+
spool_id: rewardPoolFields.spool_id,
|
|
167
192
|
});
|
|
168
193
|
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
const
|
|
194
|
+
const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
|
|
195
|
+
const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
196
|
+
|
|
197
|
+
const calculatedRewardPoolData = calculateSpoolRewardPoolData(
|
|
173
198
|
parsedSpoolData,
|
|
174
|
-
|
|
175
|
-
|
|
199
|
+
parsedSpoolRewardPoolData,
|
|
200
|
+
calculatedSpoolData,
|
|
201
|
+
rewardCoinPrice,
|
|
202
|
+
rewardCoinDecimal
|
|
176
203
|
);
|
|
177
204
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
marketCoinName: marketCoinName,
|
|
201
|
-
symbol: query.utils.parseSymbol(marketCoinName),
|
|
202
|
-
coinType: query.utils.parseCoinType(coinName),
|
|
203
|
-
marketCoinType: query.utils.parseMarketCoinType(coinName),
|
|
204
|
-
rewardCoinType: isMarketCoin(rewardCoinName)
|
|
205
|
-
? query.utils.parseMarketCoinType(rewardCoinName)
|
|
206
|
-
: query.utils.parseCoinType(rewardCoinName),
|
|
207
|
-
coinDecimal: query.utils.getCoinDecimal(coinName),
|
|
208
|
-
rewardCoinDecimal: query.utils.getCoinDecimal(rewardCoinName),
|
|
209
|
-
coinPrice: coinPrices?.[coinName] ?? 0,
|
|
210
|
-
marketCoinPrice: marketCoinPrice,
|
|
211
|
-
rewardCoinPrice: rewardCoinPrice,
|
|
212
|
-
maxPoint: parsedSpoolData.maxPoint,
|
|
213
|
-
distributedPoint: parsedSpoolData.distributedPoint,
|
|
214
|
-
maxStake: parsedSpoolData.maxStake,
|
|
215
|
-
...calculatedSpoolData,
|
|
216
|
-
exchangeRateNumerator:
|
|
217
|
-
parsedSpoolRewardPoolData.exchangeRateNumerator,
|
|
218
|
-
exchangeRateDenominator:
|
|
219
|
-
parsedSpoolRewardPoolData.exchangeRateDenominator,
|
|
220
|
-
...calculatedRewardPoolData,
|
|
221
|
-
};
|
|
222
|
-
}
|
|
205
|
+
spool = {
|
|
206
|
+
marketCoinName: marketCoinName,
|
|
207
|
+
symbol: query.utils.parseSymbol(marketCoinName),
|
|
208
|
+
coinType: query.utils.parseCoinType(coinName),
|
|
209
|
+
marketCoinType: query.utils.parseMarketCoinType(coinName),
|
|
210
|
+
rewardCoinType: isMarketCoin(rewardCoinName)
|
|
211
|
+
? query.utils.parseMarketCoinType(rewardCoinName)
|
|
212
|
+
: query.utils.parseCoinType(rewardCoinName),
|
|
213
|
+
coinDecimal: query.utils.getCoinDecimal(coinName),
|
|
214
|
+
rewardCoinDecimal: query.utils.getCoinDecimal(rewardCoinName),
|
|
215
|
+
coinPrice: coinPrices?.[coinName] ?? 0,
|
|
216
|
+
marketCoinPrice: marketCoinPrice,
|
|
217
|
+
rewardCoinPrice: rewardCoinPrice,
|
|
218
|
+
maxPoint: parsedSpoolData.maxPoint,
|
|
219
|
+
distributedPoint: parsedSpoolData.distributedPoint,
|
|
220
|
+
maxStake: parsedSpoolData.maxStake,
|
|
221
|
+
...calculatedSpoolData,
|
|
222
|
+
exchangeRateNumerator: parsedSpoolRewardPoolData.exchangeRateNumerator,
|
|
223
|
+
exchangeRateDenominator:
|
|
224
|
+
parsedSpoolRewardPoolData.exchangeRateDenominator,
|
|
225
|
+
...calculatedRewardPoolData,
|
|
226
|
+
};
|
|
223
227
|
}
|
|
224
228
|
}
|
|
225
229
|
|
|
@@ -305,13 +309,6 @@ export const getStakeAccounts = async (
|
|
|
305
309
|
{} as Record<string, SupportStakeMarketCoins>
|
|
306
310
|
);
|
|
307
311
|
|
|
308
|
-
// const stakeObjectIds: string[] = stakeObjectsResponse
|
|
309
|
-
// .map((ref: any) => ref?.data?.objectId)
|
|
310
|
-
// .filter((id: any) => id !== undefined);
|
|
311
|
-
// const stakeObjects = await utils.cache.queryGetObjects(stakeObjectIds, {
|
|
312
|
-
// showContent: true,
|
|
313
|
-
// showType: true,
|
|
314
|
-
// });
|
|
315
312
|
for (const stakeObject of stakeObjectsResponse.map((ref) => ref.data)) {
|
|
316
313
|
const id = stakeObject?.objectId;
|
|
317
314
|
const type = stakeObject?.type!;
|
|
@@ -237,7 +237,7 @@ const getTotalVeScaTreasuryAmount = async (
|
|
|
237
237
|
});
|
|
238
238
|
|
|
239
239
|
const results = res.results;
|
|
240
|
-
if (results && results[1]
|
|
240
|
+
if (results && results[1]?.returnValues) {
|
|
241
241
|
const value = Uint8Array.from(results[1].returnValues[0][0]);
|
|
242
242
|
const type = results[1].returnValues[0][1];
|
|
243
243
|
assert(type === 'u64', 'Result type is not u64');
|
package/src/types/query/core.ts
CHANGED
|
File without changes
|
|
File without changes
|