@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.
@@ -17,12 +17,10 @@ export declare const queryKeys: {
17
17
  typeArgs: string | undefined;
18
18
  })[];
19
19
  getObject: (objectId?: string, options?: SuiObjectDataOptions) => (string | {
20
- options: SuiObjectDataOptions | undefined;
21
20
  objectId: string | undefined;
22
- })[];
23
- getObjects: (objectIds?: string[], walletAddress?: string, options?: SuiObjectDataOptions) => (string | {
24
- walletAddress: string | undefined;
25
21
  options: SuiObjectDataOptions | undefined;
22
+ })[];
23
+ getObjects: (objectIds?: string[]) => (string | {
26
24
  objectIds: string;
27
25
  })[];
28
26
  getOwnedObjects: (input?: Partial<GetOwnedObjectsParams>) => (string | {
package/dist/index.js CHANGED
@@ -812,14 +812,12 @@ var queryKeys = {
812
812
  getObject: (objectId, options) => [
813
813
  "rpc",
814
814
  "getObject",
815
- { options, objectId }
815
+ { objectId, options }
816
816
  ],
817
- getObjects: (objectIds, walletAddress, options) => [
817
+ getObjects: (objectIds) => [
818
818
  "rpc",
819
819
  "getObjects",
820
820
  {
821
- walletAddress,
822
- options,
823
821
  objectIds: JSON.stringify(objectIds ?? void 0)
824
822
  }
825
823
  ],
@@ -1393,6 +1391,20 @@ var newSuiKit = (params) => {
1393
1391
  // src/models/scallopCache.ts
1394
1392
  var DEFAULT_TOKENS_PER_INTERVAL = 10;
1395
1393
  var DEFAULT_INTERVAL_IN_MS = 250;
1394
+ var deepMergeObject = (curr, update) => {
1395
+ const result = { ...curr };
1396
+ for (const key in update) {
1397
+ if (update[key] && typeof update[key] === "object" && !Array.isArray(update[key])) {
1398
+ result[key] = deepMergeObject(
1399
+ curr[key] || {},
1400
+ update[key]
1401
+ );
1402
+ } else {
1403
+ result[key] = update[key];
1404
+ }
1405
+ }
1406
+ return result;
1407
+ };
1396
1408
  var ScallopCache = class {
1397
1409
  constructor(params, instance) {
1398
1410
  this.tokensPerInterval = DEFAULT_TOKENS_PER_INTERVAL;
@@ -1544,7 +1556,8 @@ var ScallopCache = class {
1544
1556
  options = {
1545
1557
  ...options,
1546
1558
  showOwner: true,
1547
- showContent: true
1559
+ showContent: true,
1560
+ showType: true
1548
1561
  };
1549
1562
  return this.queryClient.fetchQuery({
1550
1563
  retry: this.retryFn,
@@ -1565,38 +1578,36 @@ var ScallopCache = class {
1565
1578
  * @param objectIds
1566
1579
  * @returns Promise<SuiObjectData[]>
1567
1580
  */
1568
- async queryGetObjects(objectIds, options = {
1569
- showContent: true
1570
- }) {
1581
+ async queryGetObjects(objectIds) {
1571
1582
  if (objectIds.length === 0)
1572
1583
  return [];
1584
+ const options = {
1585
+ showContent: true,
1586
+ showOwner: true,
1587
+ showType: true
1588
+ };
1573
1589
  return this.queryClient.fetchQuery({
1574
1590
  retry: this.retryFn,
1575
1591
  retryDelay: 1e3,
1576
- queryKey: queryKeys.rpc.getObjects(
1577
- objectIds,
1578
- this.walletAddress,
1579
- options
1580
- ),
1592
+ queryKey: queryKeys.rpc.getObjects(objectIds),
1581
1593
  queryFn: async () => {
1582
1594
  const results = await this.callWithRateLimit(
1583
1595
  async () => await this.suiKit.getObjects(objectIds, options)
1584
1596
  );
1585
1597
  if (results) {
1586
1598
  results.forEach((result) => {
1587
- this.queryClient.setQueriesData(
1588
- {
1589
- exact: false,
1590
- queryKey: queryKeys.rpc.getObject(result.objectId, options)
1591
- },
1592
- {
1593
- data: result,
1594
- error: null
1595
- },
1596
- {
1597
- updatedAt: Date.now()
1598
- }
1599
- );
1599
+ const queryKey = queryKeys.rpc.getObject(result.objectId);
1600
+ const prevDatas = this.queryClient.getQueriesData({
1601
+ exact: false,
1602
+ queryKey
1603
+ });
1604
+ prevDatas.forEach(([key, prevData]) => {
1605
+ this.queryClient.setQueryData(
1606
+ key,
1607
+ deepMergeObject(prevData, { data: result, error: null }),
1608
+ { updatedAt: Date.now() }
1609
+ );
1610
+ });
1600
1611
  });
1601
1612
  }
1602
1613
  return results;
@@ -1621,22 +1632,18 @@ var ScallopCache = class {
1621
1632
  results.data.filter(
1622
1633
  (result) => !!result.data
1623
1634
  ).forEach((result) => {
1624
- this.queryClient.setQueriesData(
1625
- {
1626
- exact: false,
1627
- queryKey: queryKeys.rpc.getObject(
1628
- result.data.objectId,
1629
- input.options ?? {}
1630
- )
1631
- },
1632
- {
1633
- data: result.data,
1634
- error: null
1635
- },
1636
- {
1637
- updatedAt: Date.now()
1638
- }
1639
- );
1635
+ const queryKey = queryKeys.rpc.getObject(result.data.objectId);
1636
+ const prevDatas = this.queryClient.getQueriesData({
1637
+ exact: false,
1638
+ queryKey
1639
+ });
1640
+ prevDatas.forEach(([key, prevData]) => {
1641
+ this.queryClient.setQueryData(
1642
+ key,
1643
+ deepMergeObject(prevData, { data: result.data, error: null }),
1644
+ { updatedAt: Date.now() }
1645
+ );
1646
+ });
1640
1647
  });
1641
1648
  }
1642
1649
  return results;
@@ -1665,22 +1672,18 @@ var ScallopCache = class {
1665
1672
  () => this.client.getDynamicFieldObject(input)
1666
1673
  );
1667
1674
  if (result?.data) {
1668
- this.queryClient.setQueriesData(
1669
- {
1670
- exact: false,
1671
- queryKey: queryKeys.rpc.getObject(result?.data.objectId, {
1672
- showContent: true,
1673
- showOwner: true
1674
- })
1675
- },
1676
- {
1677
- data: result.data,
1678
- error: null
1679
- },
1680
- {
1681
- updatedAt: Date.now()
1682
- }
1683
- );
1675
+ const queryKey = queryKeys.rpc.getObject(result.data.objectId);
1676
+ const prevDatas = this.queryClient.getQueriesData({
1677
+ exact: false,
1678
+ queryKey
1679
+ });
1680
+ prevDatas.forEach(([key, prevData]) => {
1681
+ this.queryClient.setQueryData(
1682
+ key,
1683
+ deepMergeObject(prevData, { data: result.data, error: null }),
1684
+ { updatedAt: Date.now() }
1685
+ );
1686
+ });
1684
1687
  }
1685
1688
  return result;
1686
1689
  }
@@ -3141,12 +3144,7 @@ var getBindedObligationId = async ({
3141
3144
  const borrowIncentiveObjectId = address.get("borrowIncentive.object");
3142
3145
  const incentivePoolsId = address.get("borrowIncentive.incentivePools");
3143
3146
  const veScaObjId = address.get("vesca.object");
3144
- const incentivePoolsResponse = await address.cache.queryGetObject(
3145
- incentivePoolsId,
3146
- {
3147
- showContent: true
3148
- }
3149
- );
3147
+ const incentivePoolsResponse = await address.cache.queryGetObject(incentivePoolsId);
3150
3148
  if (incentivePoolsResponse?.data?.content?.dataType !== "moveObject")
3151
3149
  return null;
3152
3150
  const incentivePoolFields = incentivePoolsResponse.data.content.fields;
@@ -3173,12 +3171,7 @@ var getBindedVeScaKey = async ({
3173
3171
  const borrowIncentiveObjectId = address.get("borrowIncentive.object");
3174
3172
  const incentiveAccountsId = address.get("borrowIncentive.incentiveAccounts");
3175
3173
  const corePkg = address.get("core.object");
3176
- const incentiveAccountsObject = await address.cache.queryGetObject(
3177
- incentiveAccountsId,
3178
- {
3179
- showContent: true
3180
- }
3181
- );
3174
+ const incentiveAccountsObject = await address.cache.queryGetObject(incentiveAccountsId);
3182
3175
  if (incentiveAccountsObject?.data?.content?.dataType !== "moveObject")
3183
3176
  return null;
3184
3177
  const incentiveAccountsTableId = incentiveAccountsObject.data.content.fields.accounts.fields.id.id;
@@ -3363,11 +3356,11 @@ var getBorrowLimit = async (utils, poolName) => {
3363
3356
  };
3364
3357
 
3365
3358
  // src/queries/objectsQuery.ts
3366
- var queryMultipleObjects = async (cache, objectIds, options, partitionSize = 50) => {
3359
+ var queryMultipleObjects = async (cache, objectIds, partitionSize = 50) => {
3367
3360
  const objectIdsPartition = partitionArray(objectIds, partitionSize);
3368
3361
  const objects = [];
3369
3362
  for (const objectIds2 of objectIdsPartition) {
3370
- const result = await cache.queryGetObjects(objectIds2, options);
3363
+ const result = await cache.queryGetObjects(objectIds2);
3371
3364
  objects.push(...result);
3372
3365
  }
3373
3366
  return objects;
@@ -3838,9 +3831,7 @@ var getMarketCollaterals = async (query, collateralCoinNames = [...SUPPORT_COLLA
3838
3831
  Object.values(marketCollateralsIndexer).forEach(updateMarketCollateral);
3839
3832
  return marketCollaterals;
3840
3833
  }
3841
- const marketObjectResponse = await query.cache.queryGetObject(marketId, {
3842
- showContent: true
3843
- });
3834
+ const marketObjectResponse = await query.cache.queryGetObject(marketId);
3844
3835
  await Promise.allSettled(
3845
3836
  collateralCoinNames.map(async (collateralCoinName) => {
3846
3837
  const marketCollateral = await getMarketCollateral(
@@ -3868,9 +3859,7 @@ var getMarketCollateral = async (query, collateralCoinName, indexer = false, mar
3868
3859
  return marketCollateralIndexer;
3869
3860
  }
3870
3861
  const marketId = query.address.get("core.market");
3871
- marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
3872
- showContent: true
3873
- }))?.data;
3862
+ marketObject = marketObject || (await query.cache.queryGetObject(marketId))?.data;
3874
3863
  if (!(marketObject && marketObject.content?.dataType === "moveObject"))
3875
3864
  throw new Error(`Failed to fetch marketObject`);
3876
3865
  const fields = marketObject.content.fields;
@@ -3973,10 +3962,7 @@ var getObligations = async ({
3973
3962
  address.cache,
3974
3963
  keyObjects.map((ref) => ref.data?.content).filter(
3975
3964
  (content) => content?.dataType === "moveObject"
3976
- ).map((content) => content.fields.ownership.fields.of),
3977
- {
3978
- showContent: true
3979
- }
3965
+ ).map((content) => content.fields.ownership.fields.of)
3980
3966
  );
3981
3967
  await Promise.allSettled(
3982
3968
  keyObjects.map(async ({ data }, idx) => {
@@ -3996,9 +3982,7 @@ var getObligations = async ({
3996
3982
  return obligations;
3997
3983
  };
3998
3984
  var getObligationLocked = async (cache, obligation) => {
3999
- const obligationObjectData = typeof obligation === "string" ? (await cache.queryGetObject(obligation, {
4000
- showContent: true
4001
- }))?.data : obligation;
3985
+ const obligationObjectData = typeof obligation === "string" ? (await cache.queryGetObject(obligation))?.data : obligation;
4002
3986
  let obligationLocked = false;
4003
3987
  if (obligationObjectData && obligationObjectData?.content?.dataType === "moveObject" && "lock_key" in obligationObjectData.content.fields) {
4004
3988
  obligationLocked = Boolean(obligationObjectData.content.fields.lock_key);
@@ -4083,14 +4067,10 @@ var getFlashLoanFees = async (query, assetNames) => {
4083
4067
  return FlashLoanFeeObjectMap[assetName];
4084
4068
  }
4085
4069
  }).filter((t) => !!t);
4086
- const flashloanFeeObjects = await query.cache.queryGetObjects(objIds, {
4087
- showContent: true
4088
- });
4070
+ const flashloanFeeObjects = await query.cache.queryGetObjects(objIds);
4089
4071
  if (missingAssets.length > 0) {
4090
4072
  const marketObjectId = query.address.get("core.market");
4091
- const marketObjectRes = await query.cache.queryGetObject(marketObjectId, {
4092
- showContent: true
4093
- });
4073
+ const marketObjectRes = await query.cache.queryGetObject(marketObjectId);
4094
4074
  if (marketObjectRes?.data?.content?.dataType !== "moveObject")
4095
4075
  throw new Error("Failed to get market object");
4096
4076
  const vault = marketObjectRes.data.content.fields.vault;
@@ -4104,9 +4084,7 @@ var getFlashLoanFees = async (query, assetNames) => {
4104
4084
  return !!assetTypeMap[assetType];
4105
4085
  }).map((field) => field.objectId) ?? [];
4106
4086
  flashloanFeeObjects.push(
4107
- ...await query.cache.queryGetObjects(dynamicFieldObjectIds, {
4108
- showContent: true
4109
- })
4087
+ ...await query.cache.queryGetObjects(dynamicFieldObjectIds)
4110
4088
  );
4111
4089
  }
4112
4090
  return flashloanFeeObjects.reduce(
@@ -4138,9 +4116,7 @@ var userRewardFieldsZod = import_zod4.z.object({
4138
4116
  }).transform((value) => (0, import_bignumber4.default)(value.value).shiftedBy(-9).toNumber());
4139
4117
  var getLoyaltyProgramInformations = async (query, veScaKey) => {
4140
4118
  const rewardPool = query.address.get("loyaltyProgram.rewardPool");
4141
- const rewardPoolObject = await query.cache.queryGetObject(rewardPool, {
4142
- showContent: true
4143
- });
4119
+ const rewardPoolObject = await query.cache.queryGetObject(rewardPool);
4144
4120
  if (rewardPoolObject?.data?.content?.dataType !== "moveObject")
4145
4121
  return null;
4146
4122
  const rewardPoolFields = rewardPoolObject.data.content.fields;
@@ -4890,9 +4866,7 @@ var getPythPrice = async ({
4890
4866
  const pythFeedObjectId = address.get(
4891
4867
  `core.coins.${assetCoinName}.oracle.pyth.feedObject`
4892
4868
  );
4893
- priceFeedObject = priceFeedObject || (await address.cache.queryGetObject(pythFeedObjectId, {
4894
- showContent: true
4895
- }))?.data;
4869
+ priceFeedObject = priceFeedObject || (await address.cache.queryGetObject(pythFeedObjectId))?.data;
4896
4870
  if (priceFeedObject) {
4897
4871
  const priceFeedPoolObject = priceFeedObject;
4898
4872
  if (priceFeedPoolObject.content && "fields" in priceFeedPoolObject.content) {
@@ -4934,8 +4908,7 @@ var getPythPrices = async ({
4934
4908
  {}
4935
4909
  );
4936
4910
  const priceFeedObjects = await address.cache.queryGetObjects(
4937
- Object.keys(pythPriceFeedIds),
4938
- { showContent: true }
4911
+ Object.keys(pythPriceFeedIds)
4939
4912
  );
4940
4913
  const assetToPriceFeedMapping = priceFeedObjects.reduce(
4941
4914
  (prev, priceFeedObject) => {
@@ -5375,10 +5348,7 @@ var getStakePool = async ({
5375
5348
  }, marketCoinName) => {
5376
5349
  const poolId = utils.address.get(`spool.pools.${marketCoinName}.id`);
5377
5350
  let stakePool = void 0;
5378
- const stakePoolObjectResponse = await utils.cache.queryGetObject(poolId, {
5379
- showContent: true,
5380
- showType: true
5381
- });
5351
+ const stakePoolObjectResponse = await utils.cache.queryGetObject(poolId);
5382
5352
  if (stakePoolObjectResponse?.data) {
5383
5353
  const stakePoolObject = stakePoolObjectResponse.data;
5384
5354
  const id = stakePoolObject.objectId;
@@ -5420,13 +5390,7 @@ var getStakeRewardPool = async ({
5420
5390
  `spool.pools.${marketCoinName}.rewardPoolId`
5421
5391
  );
5422
5392
  let stakeRewardPool = void 0;
5423
- const stakeRewardPoolObjectResponse = await utils.cache.queryGetObject(
5424
- poolId,
5425
- {
5426
- showContent: true,
5427
- showType: true
5428
- }
5429
- );
5393
+ const stakeRewardPoolObjectResponse = await utils.cache.queryGetObject(poolId);
5430
5394
  if (stakeRewardPoolObjectResponse?.data) {
5431
5395
  const stakeRewardPoolObject = stakeRewardPoolObjectResponse.data;
5432
5396
  const id = stakeRewardPoolObject.objectId;
@@ -5563,7 +5527,7 @@ var getTotalVeScaTreasuryAmount = async (utils, veScaTreasury) => {
5563
5527
  const resolvedRefreshArgs = await Promise.all(
5564
5528
  refreshArgs.map(async (arg) => {
5565
5529
  if (typeof arg === "string") {
5566
- return (await utils.cache.queryGetObject(arg, { showContent: true }))?.data;
5530
+ return (await utils.cache.queryGetObject(arg))?.data;
5567
5531
  }
5568
5532
  return arg;
5569
5533
  })
@@ -5571,7 +5535,7 @@ var getTotalVeScaTreasuryAmount = async (utils, veScaTreasury) => {
5571
5535
  const resolvedVeScaAmountArgs = await Promise.all(
5572
5536
  veScaAmountArgs.map(async (arg) => {
5573
5537
  if (typeof arg === "string") {
5574
- return (await utils.cache.queryGetObject(arg, { showContent: true }))?.data;
5538
+ return (await utils.cache.queryGetObject(arg))?.data;
5575
5539
  }
5576
5540
  return arg;
5577
5541
  })
@@ -5603,9 +5567,7 @@ var getTotalVeScaTreasuryAmount = async (utils, veScaTreasury) => {
5603
5567
  };
5604
5568
  var getVeScaTreasuryInfo = async (utils) => {
5605
5569
  const veScaTreasuryId = utils.address.get("vesca.treasury");
5606
- const veScaTreasury = await utils.cache.queryGetObject(veScaTreasuryId, {
5607
- showContent: true
5608
- });
5570
+ const veScaTreasury = await utils.cache.queryGetObject(veScaTreasuryId);
5609
5571
  if (!veScaTreasury || veScaTreasury.data?.content?.dataType !== "moveObject")
5610
5572
  return null;
5611
5573
  const treasuryFields = veScaTreasury.data.content.fields;
@@ -5629,9 +5591,7 @@ var getVeScaTreasuryInfo = async (utils) => {
5629
5591
  var getAllAddresses = async (query) => {
5630
5592
  const results = {};
5631
5593
  const marketId = query.address.get("core.market");
5632
- const marketObject = (await query.cache.queryGetObject(marketId, {
5633
- showContent: true
5634
- }))?.data;
5594
+ const marketObject = (await query.cache.queryGetObject(marketId))?.data;
5635
5595
  if (!(marketObject && marketObject.content?.dataType === "moveObject"))
5636
5596
  throw new Error(`Failed to fetch marketObject`);
5637
5597
  const fields = marketObject.content.fields;