@scallop-io/sui-scallop-sdk 0.47.5 → 0.47.7

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.js CHANGED
@@ -1013,6 +1013,25 @@ var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVA
1013
1013
  return tryRequest();
1014
1014
  };
1015
1015
 
1016
+ // src/utils/indexer.ts
1017
+ async function callMethodWithIndexerFallback(method, context, ...args) {
1018
+ const indexer = args[args.length - 1];
1019
+ if (indexer) {
1020
+ try {
1021
+ return await method.apply(context, args);
1022
+ } catch (_e) {
1023
+ console.warn("Indexer requests failed. Retrying without indexer..");
1024
+ return await method.apply(context, [...args.slice(0, -1), false]);
1025
+ }
1026
+ }
1027
+ return await method.apply(context, args);
1028
+ }
1029
+ function withIndexerFallback(method) {
1030
+ return (...args) => {
1031
+ return callMethodWithIndexerFallback(method, this, ...args);
1032
+ };
1033
+ }
1034
+
1016
1035
  // src/models/scallopCache.ts
1017
1036
  var ScallopCache = class {
1018
1037
  constructor(suiKit, walletAddress, cacheOptions, tokenBucket) {
@@ -2009,7 +2028,7 @@ var EMPTY_ADDRESSES = {
2009
2028
  };
2010
2029
  var ScallopAddress = class {
2011
2030
  constructor(params, instance) {
2012
- const { id, auth, network } = params;
2031
+ const { id, auth, network, forceInterface } = params;
2013
2032
  this.cache = instance?.cache ?? new ScallopCache(
2014
2033
  instance?.suiKit ?? new import_sui_kit2.SuiKit({}),
2015
2034
  void 0,
@@ -2030,6 +2049,17 @@ var ScallopAddress = class {
2030
2049
  this._addressesMap = USE_TEST_ADDRESS ? /* @__PURE__ */ new Map([["mainnet", TEST_ADDRESSES]]) : /* @__PURE__ */ new Map();
2031
2050
  if (USE_TEST_ADDRESS)
2032
2051
  this._currentAddresses = TEST_ADDRESSES;
2052
+ if (forceInterface) {
2053
+ for (const [network2, addresses] of Object.entries(
2054
+ forceInterface
2055
+ )) {
2056
+ if (["localnet", "devnet", "testnet", "mainnet"].includes(network2)) {
2057
+ if (network2 === this._network)
2058
+ this._currentAddresses = addresses;
2059
+ this._addressesMap.set(network2, addresses);
2060
+ }
2061
+ }
2062
+ }
2033
2063
  }
2034
2064
  /**
2035
2065
  * Get addresses API id.
@@ -4372,7 +4402,8 @@ var ScallopUtils = class {
4372
4402
  this.address = instance?.address ?? new ScallopAddress(
4373
4403
  {
4374
4404
  id: params?.addressesId || ADDRESSES_ID,
4375
- network: params?.networkType
4405
+ network: params?.networkType,
4406
+ forceInterface: params?.forceAddressesInterface
4376
4407
  },
4377
4408
  {
4378
4409
  cache: this.cache
@@ -6678,7 +6709,8 @@ var ScallopQuery = class {
6678
6709
  this.address = new ScallopAddress(
6679
6710
  {
6680
6711
  id: params?.addressesId || ADDRESSES_ID,
6681
- network: params?.networkType
6712
+ network: params?.networkType,
6713
+ forceInterface: params?.forceAddressesInterface
6682
6714
  },
6683
6715
  {
6684
6716
  cache: this.cache
@@ -6689,7 +6721,36 @@ var ScallopQuery = class {
6689
6721
  });
6690
6722
  }
6691
6723
  this.indexer = instance?.indexer ?? new ScallopIndexer(this.params, { cache: this.cache });
6724
+ this.queryMarket = withIndexerFallback.call(this, this.queryMarket);
6725
+ this.getMarketPools = withIndexerFallback.call(this, this.getMarketPools);
6726
+ this.getMarketPool = withIndexerFallback.call(this, this.getMarketPool);
6727
+ this.getMarketCollaterals = withIndexerFallback.call(
6728
+ this,
6729
+ this.getMarketCollaterals
6730
+ );
6731
+ this.getMarketCollateral = withIndexerFallback.call(
6732
+ this,
6733
+ this.getMarketCollateral
6734
+ );
6735
+ this.getSpools = withIndexerFallback.call(this, this.getSpools);
6736
+ this.getSpool = withIndexerFallback.call(this, this.getSpool);
6737
+ this.getBorrowIncentivePools = withIndexerFallback.call(
6738
+ this,
6739
+ this.getBorrowIncentivePools
6740
+ );
6741
+ this.getLendings = withIndexerFallback.call(this, this.getLendings);
6742
+ this.getLending = withIndexerFallback.call(this, this.getLending);
6743
+ this.getObligationAccounts = withIndexerFallback.call(
6744
+ this,
6745
+ this.getObligationAccounts
6746
+ );
6747
+ this.getObligationAccount = withIndexerFallback.call(
6748
+ this,
6749
+ this.getObligationAccount
6750
+ );
6751
+ this.getTvl = withIndexerFallback.call(this, this.getTvl);
6692
6752
  }
6753
+ /* ========================================================== */
6693
6754
  /**
6694
6755
  * Request the scallop API to initialize data.
6695
6756
  *
@@ -7169,7 +7230,8 @@ var ScallopBuilder = class {
7169
7230
  this.address = new ScallopAddress(
7170
7231
  {
7171
7232
  id: params?.addressesId || ADDRESSES_ID,
7172
- network: params?.networkType
7233
+ network: params?.networkType,
7234
+ forceInterface: params?.forceAddressesInterface
7173
7235
  },
7174
7236
  {
7175
7237
  cache: this.cache
@@ -7316,7 +7378,8 @@ var ScallopClient = class {
7316
7378
  this.address = new ScallopAddress(
7317
7379
  {
7318
7380
  id: params?.addressesId || ADDRESSES_ID,
7319
- network: params?.networkType
7381
+ network: params?.networkType,
7382
+ forceInterface: params?.forceAddressesInterface
7320
7383
  },
7321
7384
  {
7322
7385
  cache: this.cache
@@ -7979,7 +8042,8 @@ var Scallop = class {
7979
8042
  this.address = new ScallopAddress(
7980
8043
  {
7981
8044
  id: params?.addressesId || ADDRESSES_ID,
7982
- network: params?.networkType
8045
+ network: params?.networkType,
8046
+ forceInterface: params?.forceAddressesInterface
7983
8047
  },
7984
8048
  { cache: this.cache }
7985
8049
  );