@scallop-io/sui-scallop-sdk 1.3.2-alpha.2 → 1.3.2
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/queryKeys.d.ts +1 -4
- package/dist/index.js +176 -168
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +176 -168
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/builders/spoolBuilder.ts +4 -0
- package/src/constants/queryKeys.ts +1 -4
- package/src/models/scallopClient.ts +4 -4
- package/src/models/scallopUtils.ts +4 -2
- package/src/queries/coreQuery.ts +6 -4
- package/src/queries/sCoinQuery.ts +1 -1
- package/src/queries/spoolQuery.ts +76 -79
- package/src/queries/vescaQuery.ts +1 -1
package/package.json
CHANGED
|
@@ -213,6 +213,10 @@ const generateSpoolQuickMethod: GenerateSpoolQuickMethod = ({
|
|
|
213
213
|
stakeAccountId
|
|
214
214
|
);
|
|
215
215
|
|
|
216
|
+
if (stakeAccountIds.length === 0) {
|
|
217
|
+
throw new Error(`No stakeAccountIds found for user ${sender}`);
|
|
218
|
+
}
|
|
219
|
+
|
|
216
220
|
if (typeof amountOrMarketCoin === 'number') {
|
|
217
221
|
// try stake market coin
|
|
218
222
|
const stakedMarketCoinAmount = await stakeHelper(
|
|
@@ -77,10 +77,7 @@ export const queryKeys = {
|
|
|
77
77
|
'getDynamicFieldObject',
|
|
78
78
|
{
|
|
79
79
|
parentId: input?.parentId,
|
|
80
|
-
name:
|
|
81
|
-
type: input?.name?.type,
|
|
82
|
-
value: input?.name?.value,
|
|
83
|
-
},
|
|
80
|
+
name: JSON.stringify(input?.name ?? undefined),
|
|
84
81
|
},
|
|
85
82
|
],
|
|
86
83
|
getTotalVeScaTreasuryAmount: (
|
|
@@ -276,7 +276,7 @@ export class ScallopClient {
|
|
|
276
276
|
txBlock.setSender(sender);
|
|
277
277
|
|
|
278
278
|
const obligations = await this.query.getObligations(sender);
|
|
279
|
-
const specificObligationId = obligationId || obligations
|
|
279
|
+
const specificObligationId = obligationId || obligations[0]?.id;
|
|
280
280
|
if (specificObligationId) {
|
|
281
281
|
await txBlock.addCollateralQuick(
|
|
282
282
|
amount,
|
|
@@ -416,7 +416,7 @@ export class ScallopClient {
|
|
|
416
416
|
this.utils.parseMarketCoinName<SupportStakeMarketCoins>(stakeCoinName);
|
|
417
417
|
const stakeAccounts =
|
|
418
418
|
await this.query.getStakeAccounts(stakeMarketCoinName);
|
|
419
|
-
const targetStakeAccount = stakeAccountId || stakeAccounts[0]
|
|
419
|
+
const targetStakeAccount = stakeAccountId || stakeAccounts[0]?.id;
|
|
420
420
|
|
|
421
421
|
const marketCoin = await txBlock.depositQuick(amount, stakeCoinName, false);
|
|
422
422
|
if (targetStakeAccount) {
|
|
@@ -696,7 +696,7 @@ export class ScallopClient {
|
|
|
696
696
|
|
|
697
697
|
const stakeAccounts =
|
|
698
698
|
await this.query.getStakeAccounts(stakeMarketCoinName);
|
|
699
|
-
const targetStakeAccount = stakeAccountId || stakeAccounts[0]
|
|
699
|
+
const targetStakeAccount = stakeAccountId || stakeAccounts[0]?.id;
|
|
700
700
|
if (targetStakeAccount) {
|
|
701
701
|
await txBlock.stakeQuick(amount, stakeMarketCoinName, targetStakeAccount);
|
|
702
702
|
} else {
|
|
@@ -1034,7 +1034,7 @@ export class ScallopClient {
|
|
|
1034
1034
|
toDestroyMarketCoin
|
|
1035
1035
|
);
|
|
1036
1036
|
|
|
1037
|
-
//
|
|
1037
|
+
// Merge with existing sCoin
|
|
1038
1038
|
await this.utils.mergeSimilarCoins(
|
|
1039
1039
|
txBlock,
|
|
1040
1040
|
sCoin,
|
|
@@ -566,10 +566,12 @@ export class ScallopUtils {
|
|
|
566
566
|
const feed = await this.cache.queryClient.fetchQuery({
|
|
567
567
|
queryKey: queryKeys.oracle.getPythLatestPriceFeed(priceId),
|
|
568
568
|
queryFn: async () => {
|
|
569
|
-
return
|
|
569
|
+
return (
|
|
570
|
+
(await pythConnection.getLatestPriceFeeds([priceId])) ?? []
|
|
571
|
+
);
|
|
570
572
|
},
|
|
571
573
|
});
|
|
572
|
-
if (feed) {
|
|
574
|
+
if (feed[0]) {
|
|
573
575
|
const data = parseDataFromPythPriceFeed(feed[0], this.address);
|
|
574
576
|
this._priceMap.set(coinName as SupportAssetCoins, {
|
|
575
577
|
price: data.price,
|
package/src/queries/coreQuery.ts
CHANGED
|
@@ -38,7 +38,7 @@ import {
|
|
|
38
38
|
} from '../types';
|
|
39
39
|
import BigNumber from 'bignumber.js';
|
|
40
40
|
import { getSupplyLimit } from './supplyLimit';
|
|
41
|
-
import { isIsolatedAsset } from './isolatedAsset';
|
|
41
|
+
// import { isIsolatedAsset } from './isolatedAsset';
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
44
|
* Query market data.
|
|
@@ -89,7 +89,7 @@ export const queryMarket = async (
|
|
|
89
89
|
const args = [marketId];
|
|
90
90
|
|
|
91
91
|
const queryResult = await query.cache.queryInspectTxn({ queryTarget, args });
|
|
92
|
-
const marketData = queryResult?.events[0]
|
|
92
|
+
const marketData = queryResult?.events[0]?.parsedJson as
|
|
93
93
|
| MarketQueryInterface
|
|
94
94
|
| undefined;
|
|
95
95
|
|
|
@@ -156,7 +156,8 @@ export const queryMarket = async (
|
|
|
156
156
|
borrowFee: parsedMarketPoolData.borrowFee,
|
|
157
157
|
marketCoinSupplyAmount: parsedMarketPoolData.marketCoinSupplyAmount,
|
|
158
158
|
minBorrowAmount: parsedMarketPoolData.minBorrowAmount,
|
|
159
|
-
isIsolated: await isIsolatedAsset(query.utils, poolCoinName),
|
|
159
|
+
// isIsolated: await isIsolatedAsset(query.utils, poolCoinName),
|
|
160
|
+
isIsolated: false,
|
|
160
161
|
maxSupplyCoin,
|
|
161
162
|
...calculatedMarketPoolData,
|
|
162
163
|
};
|
|
@@ -494,7 +495,8 @@ export const getMarketPool = async (
|
|
|
494
495
|
marketCoinSupplyAmount: parsedMarketPoolData.marketCoinSupplyAmount,
|
|
495
496
|
minBorrowAmount: parsedMarketPoolData.minBorrowAmount,
|
|
496
497
|
maxSupplyCoin,
|
|
497
|
-
isIsolated: await isIsolatedAsset(query.utils, poolCoinName),
|
|
498
|
+
// isIsolated: await isIsolatedAsset(query.utils, poolCoinName),
|
|
499
|
+
isIsolated: false,
|
|
498
500
|
...calculatedMarketPoolData,
|
|
499
501
|
};
|
|
500
502
|
}
|
|
@@ -33,7 +33,7 @@ export const getSCoinTotalSupply = async (
|
|
|
33
33
|
typeArgs,
|
|
34
34
|
});
|
|
35
35
|
const results = queryResults?.results;
|
|
36
|
-
if (results && results[0]
|
|
36
|
+
if (results && results[0]?.returnValues) {
|
|
37
37
|
const value = Uint8Array.from(results[0].returnValues[0][0]);
|
|
38
38
|
const type = results[0].returnValues[0][1]; // should be u64
|
|
39
39
|
assert(type === 'u64', 'Result type is not u64');
|
|
@@ -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('Fail 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');
|