@scallop-io/sui-scallop-sdk 1.4.9 → 1.4.10

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/index.mjs CHANGED
@@ -722,14 +722,12 @@ var queryKeys = {
722
722
  getObject: (objectId, options) => [
723
723
  "rpc",
724
724
  "getObject",
725
- { options, objectId }
725
+ { objectId, options }
726
726
  ],
727
- getObjects: (objectIds, walletAddress, options) => [
727
+ getObjects: (objectIds) => [
728
728
  "rpc",
729
729
  "getObjects",
730
730
  {
731
- walletAddress,
732
- options,
733
731
  objectIds: JSON.stringify(objectIds ?? void 0)
734
732
  }
735
733
  ],
@@ -1307,6 +1305,20 @@ var newSuiKit = (params) => {
1307
1305
  // src/models/scallopCache.ts
1308
1306
  var DEFAULT_TOKENS_PER_INTERVAL = 10;
1309
1307
  var DEFAULT_INTERVAL_IN_MS = 250;
1308
+ var deepMergeObject = (curr, update) => {
1309
+ const result = { ...curr };
1310
+ for (const key in update) {
1311
+ if (update[key] && typeof update[key] === "object" && !Array.isArray(update[key])) {
1312
+ result[key] = deepMergeObject(
1313
+ curr[key] || {},
1314
+ update[key]
1315
+ );
1316
+ } else {
1317
+ result[key] = update[key];
1318
+ }
1319
+ }
1320
+ return result;
1321
+ };
1310
1322
  var ScallopCache = class {
1311
1323
  constructor(params, instance) {
1312
1324
  this.tokensPerInterval = DEFAULT_TOKENS_PER_INTERVAL;
@@ -1458,7 +1470,8 @@ var ScallopCache = class {
1458
1470
  options = {
1459
1471
  ...options,
1460
1472
  showOwner: true,
1461
- showContent: true
1473
+ showContent: true,
1474
+ showType: true
1462
1475
  };
1463
1476
  return this.queryClient.fetchQuery({
1464
1477
  retry: this.retryFn,
@@ -1479,38 +1492,36 @@ var ScallopCache = class {
1479
1492
  * @param objectIds
1480
1493
  * @returns Promise<SuiObjectData[]>
1481
1494
  */
1482
- async queryGetObjects(objectIds, options = {
1483
- showContent: true
1484
- }) {
1495
+ async queryGetObjects(objectIds) {
1485
1496
  if (objectIds.length === 0)
1486
1497
  return [];
1498
+ const options = {
1499
+ showContent: true,
1500
+ showOwner: true,
1501
+ showType: true
1502
+ };
1487
1503
  return this.queryClient.fetchQuery({
1488
1504
  retry: this.retryFn,
1489
1505
  retryDelay: 1e3,
1490
- queryKey: queryKeys.rpc.getObjects(
1491
- objectIds,
1492
- this.walletAddress,
1493
- options
1494
- ),
1506
+ queryKey: queryKeys.rpc.getObjects(objectIds),
1495
1507
  queryFn: async () => {
1496
1508
  const results = await this.callWithRateLimit(
1497
1509
  async () => await this.suiKit.getObjects(objectIds, options)
1498
1510
  );
1499
1511
  if (results) {
1500
1512
  results.forEach((result) => {
1501
- this.queryClient.setQueriesData(
1502
- {
1503
- exact: false,
1504
- queryKey: queryKeys.rpc.getObject(result.objectId, options)
1505
- },
1506
- {
1507
- data: result,
1508
- error: null
1509
- },
1510
- {
1511
- updatedAt: Date.now()
1512
- }
1513
- );
1513
+ const queryKey = queryKeys.rpc.getObject(result.objectId);
1514
+ const prevDatas = this.queryClient.getQueriesData({
1515
+ exact: false,
1516
+ queryKey
1517
+ });
1518
+ prevDatas.forEach(([key, prevData]) => {
1519
+ this.queryClient.setQueryData(
1520
+ key,
1521
+ deepMergeObject(prevData, { data: result, error: null }),
1522
+ { updatedAt: Date.now() }
1523
+ );
1524
+ });
1514
1525
  });
1515
1526
  }
1516
1527
  return results;
@@ -1535,22 +1546,18 @@ var ScallopCache = class {
1535
1546
  results.data.filter(
1536
1547
  (result) => !!result.data
1537
1548
  ).forEach((result) => {
1538
- this.queryClient.setQueriesData(
1539
- {
1540
- exact: false,
1541
- queryKey: queryKeys.rpc.getObject(
1542
- result.data.objectId,
1543
- input.options ?? {}
1544
- )
1545
- },
1546
- {
1547
- data: result.data,
1548
- error: null
1549
- },
1550
- {
1551
- updatedAt: Date.now()
1552
- }
1553
- );
1549
+ const queryKey = queryKeys.rpc.getObject(result.data.objectId);
1550
+ const prevDatas = this.queryClient.getQueriesData({
1551
+ exact: false,
1552
+ queryKey
1553
+ });
1554
+ prevDatas.forEach(([key, prevData]) => {
1555
+ this.queryClient.setQueryData(
1556
+ key,
1557
+ deepMergeObject(prevData, { data: result.data, error: null }),
1558
+ { updatedAt: Date.now() }
1559
+ );
1560
+ });
1554
1561
  });
1555
1562
  }
1556
1563
  return results;
@@ -1579,22 +1586,18 @@ var ScallopCache = class {
1579
1586
  () => this.client.getDynamicFieldObject(input)
1580
1587
  );
1581
1588
  if (result?.data) {
1582
- this.queryClient.setQueriesData(
1583
- {
1584
- exact: false,
1585
- queryKey: queryKeys.rpc.getObject(result?.data.objectId, {
1586
- showContent: true,
1587
- showOwner: true
1588
- })
1589
- },
1590
- {
1591
- data: result.data,
1592
- error: null
1593
- },
1594
- {
1595
- updatedAt: Date.now()
1596
- }
1597
- );
1589
+ const queryKey = queryKeys.rpc.getObject(result.data.objectId);
1590
+ const prevDatas = this.queryClient.getQueriesData({
1591
+ exact: false,
1592
+ queryKey
1593
+ });
1594
+ prevDatas.forEach(([key, prevData]) => {
1595
+ this.queryClient.setQueryData(
1596
+ key,
1597
+ deepMergeObject(prevData, { data: result.data, error: null }),
1598
+ { updatedAt: Date.now() }
1599
+ );
1600
+ });
1598
1601
  }
1599
1602
  return result;
1600
1603
  }
@@ -3055,12 +3058,7 @@ var getBindedObligationId = async ({
3055
3058
  const borrowIncentiveObjectId = address.get("borrowIncentive.object");
3056
3059
  const incentivePoolsId = address.get("borrowIncentive.incentivePools");
3057
3060
  const veScaObjId = address.get("vesca.object");
3058
- const incentivePoolsResponse = await address.cache.queryGetObject(
3059
- incentivePoolsId,
3060
- {
3061
- showContent: true
3062
- }
3063
- );
3061
+ const incentivePoolsResponse = await address.cache.queryGetObject(incentivePoolsId);
3064
3062
  if (incentivePoolsResponse?.data?.content?.dataType !== "moveObject")
3065
3063
  return null;
3066
3064
  const incentivePoolFields = incentivePoolsResponse.data.content.fields;
@@ -3087,12 +3085,7 @@ var getBindedVeScaKey = async ({
3087
3085
  const borrowIncentiveObjectId = address.get("borrowIncentive.object");
3088
3086
  const incentiveAccountsId = address.get("borrowIncentive.incentiveAccounts");
3089
3087
  const corePkg = address.get("core.object");
3090
- const incentiveAccountsObject = await address.cache.queryGetObject(
3091
- incentiveAccountsId,
3092
- {
3093
- showContent: true
3094
- }
3095
- );
3088
+ const incentiveAccountsObject = await address.cache.queryGetObject(incentiveAccountsId);
3096
3089
  if (incentiveAccountsObject?.data?.content?.dataType !== "moveObject")
3097
3090
  return null;
3098
3091
  const incentiveAccountsTableId = incentiveAccountsObject.data.content.fields.accounts.fields.id.id;
@@ -3277,11 +3270,11 @@ var getBorrowLimit = async (utils, poolName) => {
3277
3270
  };
3278
3271
 
3279
3272
  // src/queries/objectsQuery.ts
3280
- var queryMultipleObjects = async (cache, objectIds, options, partitionSize = 50) => {
3273
+ var queryMultipleObjects = async (cache, objectIds, partitionSize = 50) => {
3281
3274
  const objectIdsPartition = partitionArray(objectIds, partitionSize);
3282
3275
  const objects = [];
3283
3276
  for (const objectIds2 of objectIdsPartition) {
3284
- const result = await cache.queryGetObjects(objectIds2, options);
3277
+ const result = await cache.queryGetObjects(objectIds2);
3285
3278
  objects.push(...result);
3286
3279
  }
3287
3280
  return objects;
@@ -3752,9 +3745,7 @@ var getMarketCollaterals = async (query, collateralCoinNames = [...SUPPORT_COLLA
3752
3745
  Object.values(marketCollateralsIndexer).forEach(updateMarketCollateral);
3753
3746
  return marketCollaterals;
3754
3747
  }
3755
- const marketObjectResponse = await query.cache.queryGetObject(marketId, {
3756
- showContent: true
3757
- });
3748
+ const marketObjectResponse = await query.cache.queryGetObject(marketId);
3758
3749
  await Promise.allSettled(
3759
3750
  collateralCoinNames.map(async (collateralCoinName) => {
3760
3751
  const marketCollateral = await getMarketCollateral(
@@ -3782,9 +3773,7 @@ var getMarketCollateral = async (query, collateralCoinName, indexer = false, mar
3782
3773
  return marketCollateralIndexer;
3783
3774
  }
3784
3775
  const marketId = query.address.get("core.market");
3785
- marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
3786
- showContent: true
3787
- }))?.data;
3776
+ marketObject = marketObject || (await query.cache.queryGetObject(marketId))?.data;
3788
3777
  if (!(marketObject && marketObject.content?.dataType === "moveObject"))
3789
3778
  throw new Error(`Failed to fetch marketObject`);
3790
3779
  const fields = marketObject.content.fields;
@@ -3887,10 +3876,7 @@ var getObligations = async ({
3887
3876
  address.cache,
3888
3877
  keyObjects.map((ref) => ref.data?.content).filter(
3889
3878
  (content) => content?.dataType === "moveObject"
3890
- ).map((content) => content.fields.ownership.fields.of),
3891
- {
3892
- showContent: true
3893
- }
3879
+ ).map((content) => content.fields.ownership.fields.of)
3894
3880
  );
3895
3881
  await Promise.allSettled(
3896
3882
  keyObjects.map(async ({ data }, idx) => {
@@ -3910,9 +3896,7 @@ var getObligations = async ({
3910
3896
  return obligations;
3911
3897
  };
3912
3898
  var getObligationLocked = async (cache, obligation) => {
3913
- const obligationObjectData = typeof obligation === "string" ? (await cache.queryGetObject(obligation, {
3914
- showContent: true
3915
- }))?.data : obligation;
3899
+ const obligationObjectData = typeof obligation === "string" ? (await cache.queryGetObject(obligation))?.data : obligation;
3916
3900
  let obligationLocked = false;
3917
3901
  if (obligationObjectData && obligationObjectData?.content?.dataType === "moveObject" && "lock_key" in obligationObjectData.content.fields) {
3918
3902
  obligationLocked = Boolean(obligationObjectData.content.fields.lock_key);
@@ -3997,14 +3981,10 @@ var getFlashLoanFees = async (query, assetNames) => {
3997
3981
  return FlashLoanFeeObjectMap[assetName];
3998
3982
  }
3999
3983
  }).filter((t) => !!t);
4000
- const flashloanFeeObjects = await query.cache.queryGetObjects(objIds, {
4001
- showContent: true
4002
- });
3984
+ const flashloanFeeObjects = await query.cache.queryGetObjects(objIds);
4003
3985
  if (missingAssets.length > 0) {
4004
3986
  const marketObjectId = query.address.get("core.market");
4005
- const marketObjectRes = await query.cache.queryGetObject(marketObjectId, {
4006
- showContent: true
4007
- });
3987
+ const marketObjectRes = await query.cache.queryGetObject(marketObjectId);
4008
3988
  if (marketObjectRes?.data?.content?.dataType !== "moveObject")
4009
3989
  throw new Error("Failed to get market object");
4010
3990
  const vault = marketObjectRes.data.content.fields.vault;
@@ -4018,9 +3998,7 @@ var getFlashLoanFees = async (query, assetNames) => {
4018
3998
  return !!assetTypeMap[assetType];
4019
3999
  }).map((field) => field.objectId) ?? [];
4020
4000
  flashloanFeeObjects.push(
4021
- ...await query.cache.queryGetObjects(dynamicFieldObjectIds, {
4022
- showContent: true
4023
- })
4001
+ ...await query.cache.queryGetObjects(dynamicFieldObjectIds)
4024
4002
  );
4025
4003
  }
4026
4004
  return flashloanFeeObjects.reduce(
@@ -4052,9 +4030,7 @@ var userRewardFieldsZod = zod4.object({
4052
4030
  }).transform((value) => BigNumber4(value.value).shiftedBy(-9).toNumber());
4053
4031
  var getLoyaltyProgramInformations = async (query, veScaKey) => {
4054
4032
  const rewardPool = query.address.get("loyaltyProgram.rewardPool");
4055
- const rewardPoolObject = await query.cache.queryGetObject(rewardPool, {
4056
- showContent: true
4057
- });
4033
+ const rewardPoolObject = await query.cache.queryGetObject(rewardPool);
4058
4034
  if (rewardPoolObject?.data?.content?.dataType !== "moveObject")
4059
4035
  return null;
4060
4036
  const rewardPoolFields = rewardPoolObject.data.content.fields;
@@ -4804,9 +4780,7 @@ var getPythPrice = async ({
4804
4780
  const pythFeedObjectId = address.get(
4805
4781
  `core.coins.${assetCoinName}.oracle.pyth.feedObject`
4806
4782
  );
4807
- priceFeedObject = priceFeedObject || (await address.cache.queryGetObject(pythFeedObjectId, {
4808
- showContent: true
4809
- }))?.data;
4783
+ priceFeedObject = priceFeedObject || (await address.cache.queryGetObject(pythFeedObjectId))?.data;
4810
4784
  if (priceFeedObject) {
4811
4785
  const priceFeedPoolObject = priceFeedObject;
4812
4786
  if (priceFeedPoolObject.content && "fields" in priceFeedPoolObject.content) {
@@ -4848,8 +4822,7 @@ var getPythPrices = async ({
4848
4822
  {}
4849
4823
  );
4850
4824
  const priceFeedObjects = await address.cache.queryGetObjects(
4851
- Object.keys(pythPriceFeedIds),
4852
- { showContent: true }
4825
+ Object.keys(pythPriceFeedIds)
4853
4826
  );
4854
4827
  const assetToPriceFeedMapping = priceFeedObjects.reduce(
4855
4828
  (prev, priceFeedObject) => {
@@ -5289,10 +5262,7 @@ var getStakePool = async ({
5289
5262
  }, marketCoinName) => {
5290
5263
  const poolId = utils.address.get(`spool.pools.${marketCoinName}.id`);
5291
5264
  let stakePool = void 0;
5292
- const stakePoolObjectResponse = await utils.cache.queryGetObject(poolId, {
5293
- showContent: true,
5294
- showType: true
5295
- });
5265
+ const stakePoolObjectResponse = await utils.cache.queryGetObject(poolId);
5296
5266
  if (stakePoolObjectResponse?.data) {
5297
5267
  const stakePoolObject = stakePoolObjectResponse.data;
5298
5268
  const id = stakePoolObject.objectId;
@@ -5334,13 +5304,7 @@ var getStakeRewardPool = async ({
5334
5304
  `spool.pools.${marketCoinName}.rewardPoolId`
5335
5305
  );
5336
5306
  let stakeRewardPool = void 0;
5337
- const stakeRewardPoolObjectResponse = await utils.cache.queryGetObject(
5338
- poolId,
5339
- {
5340
- showContent: true,
5341
- showType: true
5342
- }
5343
- );
5307
+ const stakeRewardPoolObjectResponse = await utils.cache.queryGetObject(poolId);
5344
5308
  if (stakeRewardPoolObjectResponse?.data) {
5345
5309
  const stakeRewardPoolObject = stakeRewardPoolObjectResponse.data;
5346
5310
  const id = stakeRewardPoolObject.objectId;
@@ -5477,7 +5441,7 @@ var getTotalVeScaTreasuryAmount = async (utils, veScaTreasury) => {
5477
5441
  const resolvedRefreshArgs = await Promise.all(
5478
5442
  refreshArgs.map(async (arg) => {
5479
5443
  if (typeof arg === "string") {
5480
- return (await utils.cache.queryGetObject(arg, { showContent: true }))?.data;
5444
+ return (await utils.cache.queryGetObject(arg))?.data;
5481
5445
  }
5482
5446
  return arg;
5483
5447
  })
@@ -5485,7 +5449,7 @@ var getTotalVeScaTreasuryAmount = async (utils, veScaTreasury) => {
5485
5449
  const resolvedVeScaAmountArgs = await Promise.all(
5486
5450
  veScaAmountArgs.map(async (arg) => {
5487
5451
  if (typeof arg === "string") {
5488
- return (await utils.cache.queryGetObject(arg, { showContent: true }))?.data;
5452
+ return (await utils.cache.queryGetObject(arg))?.data;
5489
5453
  }
5490
5454
  return arg;
5491
5455
  })
@@ -5517,9 +5481,7 @@ var getTotalVeScaTreasuryAmount = async (utils, veScaTreasury) => {
5517
5481
  };
5518
5482
  var getVeScaTreasuryInfo = async (utils) => {
5519
5483
  const veScaTreasuryId = utils.address.get("vesca.treasury");
5520
- const veScaTreasury = await utils.cache.queryGetObject(veScaTreasuryId, {
5521
- showContent: true
5522
- });
5484
+ const veScaTreasury = await utils.cache.queryGetObject(veScaTreasuryId);
5523
5485
  if (!veScaTreasury || veScaTreasury.data?.content?.dataType !== "moveObject")
5524
5486
  return null;
5525
5487
  const treasuryFields = veScaTreasury.data.content.fields;
@@ -5543,9 +5505,7 @@ var getVeScaTreasuryInfo = async (utils) => {
5543
5505
  var getAllAddresses = async (query) => {
5544
5506
  const results = {};
5545
5507
  const marketId = query.address.get("core.market");
5546
- const marketObject = (await query.cache.queryGetObject(marketId, {
5547
- showContent: true
5548
- }))?.data;
5508
+ const marketObject = (await query.cache.queryGetObject(marketId))?.data;
5549
5509
  if (!(marketObject && marketObject.content?.dataType === "moveObject"))
5550
5510
  throw new Error(`Failed to fetch marketObject`);
5551
5511
  const fields = marketObject.content.fields;