@scallop-io/sui-scallop-sdk 1.3.2-alpha.3 → 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/dist/index.mjs
CHANGED
|
@@ -341,10 +341,7 @@ var queryKeys = {
|
|
|
341
341
|
"getDynamicFieldObject",
|
|
342
342
|
{
|
|
343
343
|
parentId: input?.parentId,
|
|
344
|
-
name:
|
|
345
|
-
type: input?.name?.type,
|
|
346
|
-
value: input?.name?.value
|
|
347
|
-
}
|
|
344
|
+
name: JSON.stringify(input?.name ?? void 0)
|
|
348
345
|
}
|
|
349
346
|
],
|
|
350
347
|
getTotalVeScaTreasuryAmount: (refreshArgs, vescaAmountArgs) => [
|
|
@@ -2315,86 +2312,6 @@ var getSupplyLimit = async (utils, poolName) => {
|
|
|
2315
2312
|
return parsedData.data.fields.value;
|
|
2316
2313
|
};
|
|
2317
2314
|
|
|
2318
|
-
// src/queries/isolatedAsset.ts
|
|
2319
|
-
import { z as zod2 } from "zod";
|
|
2320
|
-
var isolatedAssetZod = zod2.object({
|
|
2321
|
-
dataType: zod2.string(),
|
|
2322
|
-
type: zod2.string(),
|
|
2323
|
-
hasPublicTransfer: zod2.boolean(),
|
|
2324
|
-
fields: zod2.object({
|
|
2325
|
-
id: zod2.object({
|
|
2326
|
-
id: zod2.string()
|
|
2327
|
-
}),
|
|
2328
|
-
name: zod2.object({
|
|
2329
|
-
type: zod2.string()
|
|
2330
|
-
}),
|
|
2331
|
-
value: zod2.boolean()
|
|
2332
|
-
})
|
|
2333
|
-
});
|
|
2334
|
-
var ISOLATED_ASSET_KEY = "0x6e641f0dca8aedab3101d047e96439178f16301bf0b57fe8745086ff1195eb3e::market_dynamic_keys::IsolatedAssetKey";
|
|
2335
|
-
var getIsolatedAssets = async (address) => {
|
|
2336
|
-
try {
|
|
2337
|
-
const marketObject = address.get("core.market");
|
|
2338
|
-
const isolatedAssets = [];
|
|
2339
|
-
if (!marketObject)
|
|
2340
|
-
return isolatedAssets;
|
|
2341
|
-
let hasNextPage = false;
|
|
2342
|
-
let nextCursor = null;
|
|
2343
|
-
const isIsolatedDynamicField = (dynamicField) => {
|
|
2344
|
-
return dynamicField.name.type === ISOLATED_ASSET_KEY;
|
|
2345
|
-
};
|
|
2346
|
-
do {
|
|
2347
|
-
const response = await address.cache.queryGetDynamicFields({
|
|
2348
|
-
parentId: marketObject,
|
|
2349
|
-
cursor: nextCursor,
|
|
2350
|
-
limit: 10
|
|
2351
|
-
});
|
|
2352
|
-
if (!response)
|
|
2353
|
-
break;
|
|
2354
|
-
const isolatedAssetCoinTypes = response.data.filter(isIsolatedDynamicField).map(({ name }) => `0x${name.value.type.name}`);
|
|
2355
|
-
isolatedAssets.push(...isolatedAssetCoinTypes);
|
|
2356
|
-
if (response && response.hasNextPage && response.nextCursor) {
|
|
2357
|
-
hasNextPage = true;
|
|
2358
|
-
nextCursor = response.nextCursor;
|
|
2359
|
-
} else {
|
|
2360
|
-
hasNextPage = false;
|
|
2361
|
-
}
|
|
2362
|
-
} while (hasNextPage);
|
|
2363
|
-
return isolatedAssets;
|
|
2364
|
-
} catch (e) {
|
|
2365
|
-
console.error(e);
|
|
2366
|
-
return [];
|
|
2367
|
-
}
|
|
2368
|
-
};
|
|
2369
|
-
var isIsolatedAsset = async (utils, coinName) => {
|
|
2370
|
-
try {
|
|
2371
|
-
const marketObject = utils.address.get("core.market");
|
|
2372
|
-
const cachedData = utils.address.cache.queryClient.getQueryData([
|
|
2373
|
-
"getDynamicFields",
|
|
2374
|
-
marketObject
|
|
2375
|
-
]);
|
|
2376
|
-
if (cachedData) {
|
|
2377
|
-
const coinType2 = utils.parseCoinType(coinName);
|
|
2378
|
-
return cachedData.includes(coinType2);
|
|
2379
|
-
}
|
|
2380
|
-
const coinType = utils.parseCoinType(coinName).slice(2);
|
|
2381
|
-
const object = await utils.cache.queryGetDynamicFieldObject({
|
|
2382
|
-
parentId: marketObject,
|
|
2383
|
-
name: {
|
|
2384
|
-
type: ISOLATED_ASSET_KEY,
|
|
2385
|
-
value: coinType
|
|
2386
|
-
}
|
|
2387
|
-
});
|
|
2388
|
-
const parsedData = isolatedAssetZod.safeParse(object?.data?.content);
|
|
2389
|
-
if (!parsedData.success)
|
|
2390
|
-
return false;
|
|
2391
|
-
return parsedData.data.fields.value;
|
|
2392
|
-
} catch (e) {
|
|
2393
|
-
console.error(e);
|
|
2394
|
-
return false;
|
|
2395
|
-
}
|
|
2396
|
-
};
|
|
2397
|
-
|
|
2398
2315
|
// src/queries/coreQuery.ts
|
|
2399
2316
|
var queryMarket = async (query, indexer = false) => {
|
|
2400
2317
|
const coinPrices = await query.utils.getCoinPrices();
|
|
@@ -2424,7 +2341,7 @@ var queryMarket = async (query, indexer = false) => {
|
|
|
2424
2341
|
const queryTarget = `${packageId}::market_query::market_data`;
|
|
2425
2342
|
const args = [marketId];
|
|
2426
2343
|
const queryResult = await query.cache.queryInspectTxn({ queryTarget, args });
|
|
2427
|
-
const marketData = queryResult?.events[0]
|
|
2344
|
+
const marketData = queryResult?.events[0]?.parsedJson;
|
|
2428
2345
|
for (const pool of marketData?.pools ?? []) {
|
|
2429
2346
|
const coinType = normalizeStructTag3(pool.type.name);
|
|
2430
2347
|
const poolCoinName = query.utils.parseCoinNameFromType(coinType);
|
|
@@ -2479,7 +2396,8 @@ var queryMarket = async (query, indexer = false) => {
|
|
|
2479
2396
|
borrowFee: parsedMarketPoolData.borrowFee,
|
|
2480
2397
|
marketCoinSupplyAmount: parsedMarketPoolData.marketCoinSupplyAmount,
|
|
2481
2398
|
minBorrowAmount: parsedMarketPoolData.minBorrowAmount,
|
|
2482
|
-
isIsolated: await isIsolatedAsset(query.utils, poolCoinName),
|
|
2399
|
+
// isIsolated: await isIsolatedAsset(query.utils, poolCoinName),
|
|
2400
|
+
isIsolated: false,
|
|
2483
2401
|
maxSupplyCoin,
|
|
2484
2402
|
...calculatedMarketPoolData
|
|
2485
2403
|
};
|
|
@@ -2707,7 +2625,8 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
|
|
|
2707
2625
|
marketCoinSupplyAmount: parsedMarketPoolData.marketCoinSupplyAmount,
|
|
2708
2626
|
minBorrowAmount: parsedMarketPoolData.minBorrowAmount,
|
|
2709
2627
|
maxSupplyCoin,
|
|
2710
|
-
isIsolated: await isIsolatedAsset(query.utils, poolCoinName),
|
|
2628
|
+
// isIsolated: await isIsolatedAsset(query.utils, poolCoinName),
|
|
2629
|
+
isIsolated: false,
|
|
2711
2630
|
...calculatedMarketPoolData
|
|
2712
2631
|
};
|
|
2713
2632
|
}
|
|
@@ -3066,6 +2985,9 @@ var getSpools = async (query, stakeMarketCoinNames = [...SUPPORT_SPOOLS], indexe
|
|
|
3066
2985
|
var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPrices) => {
|
|
3067
2986
|
const coinName = query.utils.parseCoinName(marketCoinName);
|
|
3068
2987
|
marketPool = marketPool || await query.getMarketPool(coinName, indexer);
|
|
2988
|
+
if (!marketPool) {
|
|
2989
|
+
throw new Error("Fail to fetch marketPool");
|
|
2990
|
+
}
|
|
3069
2991
|
const poolId = query.address.get(`spool.pools.${marketCoinName}.id`);
|
|
3070
2992
|
const rewardPoolId = query.address.get(
|
|
3071
2993
|
`spool.pools.${marketCoinName}.rewardPoolId`
|
|
@@ -3075,10 +2997,10 @@ var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPr
|
|
|
3075
2997
|
if (indexer) {
|
|
3076
2998
|
const spoolIndexer = await query.indexer.getSpool(marketCoinName);
|
|
3077
2999
|
const coinName2 = query.utils.parseCoinName(marketCoinName);
|
|
3078
|
-
const
|
|
3000
|
+
const rewardCoinName2 = query.utils.getSpoolRewardCoinName(marketCoinName);
|
|
3079
3001
|
spoolIndexer.coinPrice = coinPrices?.[coinName2] || spoolIndexer.coinPrice;
|
|
3080
3002
|
spoolIndexer.marketCoinPrice = (coinPrices?.[coinName2] ?? 0) * (marketPool ? marketPool.conversionRate : 0) || spoolIndexer.marketCoinPrice;
|
|
3081
|
-
spoolIndexer.rewardCoinPrice = coinPrices?.[
|
|
3003
|
+
spoolIndexer.rewardCoinPrice = coinPrices?.[rewardCoinName2] || spoolIndexer.rewardCoinPrice;
|
|
3082
3004
|
return spoolIndexer;
|
|
3083
3005
|
}
|
|
3084
3006
|
const spoolObjectResponse = await query.cache.queryGetObjects(
|
|
@@ -3087,70 +3009,71 @@ var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPr
|
|
|
3087
3009
|
showContent: true
|
|
3088
3010
|
}
|
|
3089
3011
|
);
|
|
3090
|
-
if (
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3012
|
+
if (!(spoolObjectResponse[0] && spoolObjectResponse[1])) {
|
|
3013
|
+
throw new Error("Fail to fetch spoolObjectResponse!");
|
|
3014
|
+
}
|
|
3015
|
+
const rewardCoinName = query.utils.getSpoolRewardCoinName(marketCoinName);
|
|
3016
|
+
coinPrices = coinPrices || await query.utils.getCoinPrices([coinName, rewardCoinName]);
|
|
3017
|
+
const spoolObject = spoolObjectResponse[0];
|
|
3018
|
+
const rewardPoolObject = spoolObjectResponse[1];
|
|
3019
|
+
if (spoolObject.content && "fields" in spoolObject.content) {
|
|
3020
|
+
const spoolFields = spoolObject.content.fields;
|
|
3021
|
+
const parsedSpoolData = parseOriginSpoolData({
|
|
3022
|
+
stakeType: spoolFields.stake_type,
|
|
3023
|
+
maxDistributedPoint: spoolFields.max_distributed_point,
|
|
3024
|
+
distributedPoint: spoolFields.distributed_point,
|
|
3025
|
+
distributedPointPerPeriod: spoolFields.distributed_point_per_period,
|
|
3026
|
+
pointDistributionTime: spoolFields.point_distribution_time,
|
|
3027
|
+
maxStake: spoolFields.max_stakes,
|
|
3028
|
+
stakes: spoolFields.stakes,
|
|
3029
|
+
index: spoolFields.index,
|
|
3030
|
+
createdAt: spoolFields.created_at,
|
|
3031
|
+
lastUpdate: spoolFields.last_update
|
|
3032
|
+
});
|
|
3033
|
+
const marketCoinPrice = (coinPrices?.[coinName] ?? 0) * marketPool.conversionRate;
|
|
3034
|
+
const marketCoinDecimal = query.utils.getCoinDecimal(marketCoinName);
|
|
3035
|
+
const calculatedSpoolData = calculateSpoolData(
|
|
3036
|
+
parsedSpoolData,
|
|
3037
|
+
marketCoinPrice,
|
|
3038
|
+
marketCoinDecimal
|
|
3039
|
+
);
|
|
3040
|
+
if (rewardPoolObject.content && "fields" in rewardPoolObject.content) {
|
|
3041
|
+
const rewardPoolFields = rewardPoolObject.content.fields;
|
|
3042
|
+
const parsedSpoolRewardPoolData = parseOriginSpoolRewardPoolData({
|
|
3043
|
+
claimed_rewards: rewardPoolFields.claimed_rewards,
|
|
3044
|
+
exchange_rate_numerator: rewardPoolFields.exchange_rate_numerator,
|
|
3045
|
+
exchange_rate_denominator: rewardPoolFields.exchange_rate_denominator,
|
|
3046
|
+
rewards: rewardPoolFields.rewards,
|
|
3047
|
+
spool_id: rewardPoolFields.spool_id
|
|
3108
3048
|
});
|
|
3109
|
-
const
|
|
3110
|
-
const
|
|
3111
|
-
const
|
|
3049
|
+
const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
|
|
3050
|
+
const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
3051
|
+
const calculatedRewardPoolData = calculateSpoolRewardPoolData(
|
|
3112
3052
|
parsedSpoolData,
|
|
3053
|
+
parsedSpoolRewardPoolData,
|
|
3054
|
+
calculatedSpoolData,
|
|
3055
|
+
rewardCoinPrice,
|
|
3056
|
+
rewardCoinDecimal
|
|
3057
|
+
);
|
|
3058
|
+
spool = {
|
|
3059
|
+
marketCoinName,
|
|
3060
|
+
symbol: query.utils.parseSymbol(marketCoinName),
|
|
3061
|
+
coinType: query.utils.parseCoinType(coinName),
|
|
3062
|
+
marketCoinType: query.utils.parseMarketCoinType(coinName),
|
|
3063
|
+
rewardCoinType: isMarketCoin(rewardCoinName) ? query.utils.parseMarketCoinType(rewardCoinName) : query.utils.parseCoinType(rewardCoinName),
|
|
3064
|
+
coinDecimal: query.utils.getCoinDecimal(coinName),
|
|
3065
|
+
rewardCoinDecimal: query.utils.getCoinDecimal(rewardCoinName),
|
|
3066
|
+
coinPrice: coinPrices?.[coinName] ?? 0,
|
|
3113
3067
|
marketCoinPrice,
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
spool_id: rewardPoolFields.spool_id
|
|
3124
|
-
});
|
|
3125
|
-
const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
|
|
3126
|
-
const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
3127
|
-
const calculatedRewardPoolData = calculateSpoolRewardPoolData(
|
|
3128
|
-
parsedSpoolData,
|
|
3129
|
-
parsedSpoolRewardPoolData,
|
|
3130
|
-
calculatedSpoolData,
|
|
3131
|
-
rewardCoinPrice,
|
|
3132
|
-
rewardCoinDecimal
|
|
3133
|
-
);
|
|
3134
|
-
spool = {
|
|
3135
|
-
marketCoinName,
|
|
3136
|
-
symbol: query.utils.parseSymbol(marketCoinName),
|
|
3137
|
-
coinType: query.utils.parseCoinType(coinName),
|
|
3138
|
-
marketCoinType: query.utils.parseMarketCoinType(coinName),
|
|
3139
|
-
rewardCoinType: isMarketCoin(rewardCoinName) ? query.utils.parseMarketCoinType(rewardCoinName) : query.utils.parseCoinType(rewardCoinName),
|
|
3140
|
-
coinDecimal: query.utils.getCoinDecimal(coinName),
|
|
3141
|
-
rewardCoinDecimal: query.utils.getCoinDecimal(rewardCoinName),
|
|
3142
|
-
coinPrice: coinPrices?.[coinName] ?? 0,
|
|
3143
|
-
marketCoinPrice,
|
|
3144
|
-
rewardCoinPrice,
|
|
3145
|
-
maxPoint: parsedSpoolData.maxPoint,
|
|
3146
|
-
distributedPoint: parsedSpoolData.distributedPoint,
|
|
3147
|
-
maxStake: parsedSpoolData.maxStake,
|
|
3148
|
-
...calculatedSpoolData,
|
|
3149
|
-
exchangeRateNumerator: parsedSpoolRewardPoolData.exchangeRateNumerator,
|
|
3150
|
-
exchangeRateDenominator: parsedSpoolRewardPoolData.exchangeRateDenominator,
|
|
3151
|
-
...calculatedRewardPoolData
|
|
3152
|
-
};
|
|
3153
|
-
}
|
|
3068
|
+
rewardCoinPrice,
|
|
3069
|
+
maxPoint: parsedSpoolData.maxPoint,
|
|
3070
|
+
distributedPoint: parsedSpoolData.distributedPoint,
|
|
3071
|
+
maxStake: parsedSpoolData.maxStake,
|
|
3072
|
+
...calculatedSpoolData,
|
|
3073
|
+
exchangeRateNumerator: parsedSpoolRewardPoolData.exchangeRateNumerator,
|
|
3074
|
+
exchangeRateDenominator: parsedSpoolRewardPoolData.exchangeRateDenominator,
|
|
3075
|
+
...calculatedRewardPoolData
|
|
3076
|
+
};
|
|
3154
3077
|
}
|
|
3155
3078
|
}
|
|
3156
3079
|
return spool;
|
|
@@ -4122,7 +4045,7 @@ var getTotalValueLocked = async (query, indexer = false) => {
|
|
|
4122
4045
|
import BigNumber5 from "bignumber.js";
|
|
4123
4046
|
import { SUI_CLOCK_OBJECT_ID, SuiTxBlock as SuiTxBlock2 } from "@scallop-io/sui-kit";
|
|
4124
4047
|
import { bcs } from "@mysten/sui/bcs";
|
|
4125
|
-
import { z as
|
|
4048
|
+
import { z as zod2 } from "zod";
|
|
4126
4049
|
import assert from "assert";
|
|
4127
4050
|
var getVescaKeys = async (utils, ownerAddress) => {
|
|
4128
4051
|
const owner = ownerAddress || utils.suiKit.currentAddress();
|
|
@@ -4171,10 +4094,10 @@ var getVeScas = async ({
|
|
|
4171
4094
|
}
|
|
4172
4095
|
return result;
|
|
4173
4096
|
};
|
|
4174
|
-
var SuiObjectRefZod =
|
|
4175
|
-
objectId:
|
|
4176
|
-
digest:
|
|
4177
|
-
version:
|
|
4097
|
+
var SuiObjectRefZod = zod2.object({
|
|
4098
|
+
objectId: zod2.string(),
|
|
4099
|
+
digest: zod2.string(),
|
|
4100
|
+
version: zod2.string()
|
|
4178
4101
|
});
|
|
4179
4102
|
var getVeSca = async (utils, veScaKey, ownerAddress) => {
|
|
4180
4103
|
const tableId = utils.address.get(`vesca.tableId`);
|
|
@@ -4258,7 +4181,7 @@ var getTotalVeScaTreasuryAmount = async (utils, veScaTreasury) => {
|
|
|
4258
4181
|
}
|
|
4259
4182
|
});
|
|
4260
4183
|
const results = res.results;
|
|
4261
|
-
if (results && results[1]
|
|
4184
|
+
if (results && results[1]?.returnValues) {
|
|
4262
4185
|
const value = Uint8Array.from(results[1].returnValues[0][0]);
|
|
4263
4186
|
const type = results[1].returnValues[0][1];
|
|
4264
4187
|
assert(type === "u64", "Result type is not u64");
|
|
@@ -4308,16 +4231,16 @@ var queryVeScaKeyIdFromReferralBindings = async (address, refereeAddress) => {
|
|
|
4308
4231
|
|
|
4309
4232
|
// src/queries/loyaltyProgramQuery.ts
|
|
4310
4233
|
import BigNumber6 from "bignumber.js";
|
|
4311
|
-
import { z as
|
|
4312
|
-
var rewardPoolFieldsZod =
|
|
4313
|
-
balance:
|
|
4314
|
-
enable_claim:
|
|
4234
|
+
import { z as zod3 } from "zod";
|
|
4235
|
+
var rewardPoolFieldsZod = zod3.object({
|
|
4236
|
+
balance: zod3.string(),
|
|
4237
|
+
enable_claim: zod3.boolean()
|
|
4315
4238
|
}).transform((value) => ({
|
|
4316
4239
|
totalPoolReward: BigNumber6(value.balance).shiftedBy(-9).toNumber(),
|
|
4317
4240
|
isClaimEnabled: value.enable_claim
|
|
4318
4241
|
}));
|
|
4319
|
-
var userRewardFieldsZod =
|
|
4320
|
-
value:
|
|
4242
|
+
var userRewardFieldsZod = zod3.object({
|
|
4243
|
+
value: zod3.string()
|
|
4321
4244
|
}).transform((value) => BigNumber6(value.value).shiftedBy(-9).toNumber());
|
|
4322
4245
|
var getLoyaltyProgramInformations = async (query, veScaKey) => {
|
|
4323
4246
|
const rewardPool = query.address.get("loyaltyProgram.rewardPool");
|
|
@@ -4743,10 +4666,10 @@ var ScallopUtils = class {
|
|
|
4743
4666
|
const feed = await this.cache.queryClient.fetchQuery({
|
|
4744
4667
|
queryKey: queryKeys.oracle.getPythLatestPriceFeed(priceId),
|
|
4745
4668
|
queryFn: async () => {
|
|
4746
|
-
return await pythConnection.getLatestPriceFeeds([priceId]);
|
|
4669
|
+
return await pythConnection.getLatestPriceFeeds([priceId]) ?? [];
|
|
4747
4670
|
}
|
|
4748
4671
|
});
|
|
4749
|
-
if (feed) {
|
|
4672
|
+
if (feed[0]) {
|
|
4750
4673
|
const data = parseDataFromPythPriceFeed(feed[0], this.address);
|
|
4751
4674
|
this._priceMap.set(coinName, {
|
|
4752
4675
|
price: data.price,
|
|
@@ -5495,6 +5418,9 @@ var generateSpoolQuickMethod = ({
|
|
|
5495
5418
|
stakeMarketCoinName,
|
|
5496
5419
|
stakeAccountId
|
|
5497
5420
|
);
|
|
5421
|
+
if (stakeAccountIds.length === 0) {
|
|
5422
|
+
throw new Error(`No stakeAccountIds found for user ${sender}`);
|
|
5423
|
+
}
|
|
5498
5424
|
if (typeof amountOrMarketCoin === "number") {
|
|
5499
5425
|
const stakedMarketCoinAmount = await stakeHelper(
|
|
5500
5426
|
builder,
|
|
@@ -6633,7 +6559,7 @@ var getSCoinTotalSupply = async ({
|
|
|
6633
6559
|
typeArgs
|
|
6634
6560
|
});
|
|
6635
6561
|
const results = queryResults?.results;
|
|
6636
|
-
if (results && results[0]
|
|
6562
|
+
if (results && results[0]?.returnValues) {
|
|
6637
6563
|
const value = Uint8Array.from(results[0].returnValues[0][0]);
|
|
6638
6564
|
const type = results[0].returnValues[0][1];
|
|
6639
6565
|
assert2(type === "u64", "Result type is not u64");
|
|
@@ -6708,6 +6634,88 @@ var getSCoinSwapRate = async (query, fromSCoin, toSCoin, underlyingCoinPrice) =>
|
|
|
6708
6634
|
|
|
6709
6635
|
// src/models/scallopQuery.ts
|
|
6710
6636
|
import { normalizeSuiAddress } from "@mysten/sui/utils";
|
|
6637
|
+
|
|
6638
|
+
// src/queries/isolatedAsset.ts
|
|
6639
|
+
import { z as zod4 } from "zod";
|
|
6640
|
+
var isolatedAssetZod = zod4.object({
|
|
6641
|
+
dataType: zod4.string(),
|
|
6642
|
+
type: zod4.string(),
|
|
6643
|
+
hasPublicTransfer: zod4.boolean(),
|
|
6644
|
+
fields: zod4.object({
|
|
6645
|
+
id: zod4.object({
|
|
6646
|
+
id: zod4.string()
|
|
6647
|
+
}),
|
|
6648
|
+
name: zod4.object({
|
|
6649
|
+
type: zod4.string()
|
|
6650
|
+
}),
|
|
6651
|
+
value: zod4.boolean()
|
|
6652
|
+
})
|
|
6653
|
+
});
|
|
6654
|
+
var ISOLATED_ASSET_KEY = "0x6e641f0dca8aedab3101d047e96439178f16301bf0b57fe8745086ff1195eb3e::market_dynamic_keys::IsolatedAssetKey";
|
|
6655
|
+
var getIsolatedAssets = async (address) => {
|
|
6656
|
+
try {
|
|
6657
|
+
const marketObject = address.get("core.market");
|
|
6658
|
+
const isolatedAssets = [];
|
|
6659
|
+
if (!marketObject)
|
|
6660
|
+
return isolatedAssets;
|
|
6661
|
+
let hasNextPage = false;
|
|
6662
|
+
let nextCursor = null;
|
|
6663
|
+
const isIsolatedDynamicField = (dynamicField) => {
|
|
6664
|
+
return dynamicField.name.type === ISOLATED_ASSET_KEY;
|
|
6665
|
+
};
|
|
6666
|
+
do {
|
|
6667
|
+
const response = await address.cache.queryGetDynamicFields({
|
|
6668
|
+
parentId: marketObject,
|
|
6669
|
+
cursor: nextCursor,
|
|
6670
|
+
limit: 10
|
|
6671
|
+
});
|
|
6672
|
+
if (!response)
|
|
6673
|
+
break;
|
|
6674
|
+
const isolatedAssetCoinTypes = response.data.filter(isIsolatedDynamicField).map(({ name }) => `0x${name.value.type.name}`);
|
|
6675
|
+
isolatedAssets.push(...isolatedAssetCoinTypes);
|
|
6676
|
+
if (response && response.hasNextPage && response.nextCursor) {
|
|
6677
|
+
hasNextPage = true;
|
|
6678
|
+
nextCursor = response.nextCursor;
|
|
6679
|
+
} else {
|
|
6680
|
+
hasNextPage = false;
|
|
6681
|
+
}
|
|
6682
|
+
} while (hasNextPage);
|
|
6683
|
+
return isolatedAssets;
|
|
6684
|
+
} catch (e) {
|
|
6685
|
+
console.error(e);
|
|
6686
|
+
return [];
|
|
6687
|
+
}
|
|
6688
|
+
};
|
|
6689
|
+
var isIsolatedAsset = async (utils, coinName) => {
|
|
6690
|
+
try {
|
|
6691
|
+
const marketObject = utils.address.get("core.market");
|
|
6692
|
+
const cachedData = utils.address.cache.queryClient.getQueryData([
|
|
6693
|
+
"getDynamicFields",
|
|
6694
|
+
marketObject
|
|
6695
|
+
]);
|
|
6696
|
+
if (cachedData) {
|
|
6697
|
+
const coinType2 = utils.parseCoinType(coinName);
|
|
6698
|
+
return cachedData.includes(coinType2);
|
|
6699
|
+
}
|
|
6700
|
+
const coinType = utils.parseCoinType(coinName).slice(2);
|
|
6701
|
+
const object = await utils.cache.queryGetDynamicFieldObject({
|
|
6702
|
+
parentId: marketObject,
|
|
6703
|
+
name: {
|
|
6704
|
+
type: ISOLATED_ASSET_KEY,
|
|
6705
|
+
value: coinType
|
|
6706
|
+
}
|
|
6707
|
+
});
|
|
6708
|
+
const parsedData = isolatedAssetZod.safeParse(object?.data?.content);
|
|
6709
|
+
if (!parsedData.success)
|
|
6710
|
+
return false;
|
|
6711
|
+
return parsedData.data.fields.value;
|
|
6712
|
+
} catch (e) {
|
|
6713
|
+
console.error(e);
|
|
6714
|
+
return false;
|
|
6715
|
+
}
|
|
6716
|
+
};
|
|
6717
|
+
|
|
6718
|
+
// src/models/scallopQuery.ts
|
|
6711
6719
|
var ScallopQuery = class {
|
|
6712
6720
|
constructor(params, instance) {
|
|
6713
6721
|
this.params = params;
|
|
@@ -7544,7 +7552,7 @@ var ScallopClient = class {
|
|
|
7544
7552
|
const sender = walletAddress || this.walletAddress;
|
|
7545
7553
|
txBlock.setSender(sender);
|
|
7546
7554
|
const obligations = await this.query.getObligations(sender);
|
|
7547
|
-
const specificObligationId = obligationId || obligations
|
|
7555
|
+
const specificObligationId = obligationId || obligations[0]?.id;
|
|
7548
7556
|
if (specificObligationId) {
|
|
7549
7557
|
await txBlock.addCollateralQuick(
|
|
7550
7558
|
amount,
|
|
@@ -7615,7 +7623,7 @@ var ScallopClient = class {
|
|
|
7615
7623
|
txBlock.setSender(sender);
|
|
7616
7624
|
const stakeMarketCoinName = this.utils.parseMarketCoinName(stakeCoinName);
|
|
7617
7625
|
const stakeAccounts = await this.query.getStakeAccounts(stakeMarketCoinName);
|
|
7618
|
-
const targetStakeAccount = stakeAccountId || stakeAccounts[0]
|
|
7626
|
+
const targetStakeAccount = stakeAccountId || stakeAccounts[0]?.id;
|
|
7619
7627
|
const marketCoin = await txBlock.depositQuick(amount, stakeCoinName, false);
|
|
7620
7628
|
if (targetStakeAccount) {
|
|
7621
7629
|
await txBlock.stakeQuick(
|
|
@@ -7750,7 +7758,7 @@ var ScallopClient = class {
|
|
|
7750
7758
|
const sender = walletAddress || this.walletAddress;
|
|
7751
7759
|
txBlock.setSender(sender);
|
|
7752
7760
|
const stakeAccounts = await this.query.getStakeAccounts(stakeMarketCoinName);
|
|
7753
|
-
const targetStakeAccount = stakeAccountId || stakeAccounts[0]
|
|
7761
|
+
const targetStakeAccount = stakeAccountId || stakeAccounts[0]?.id;
|
|
7754
7762
|
if (targetStakeAccount) {
|
|
7755
7763
|
await txBlock.stakeQuick(amount, stakeMarketCoinName, targetStakeAccount);
|
|
7756
7764
|
} else {
|