@scallop-io/sui-scallop-sdk 1.4.15-rc.3 → 1.4.16

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.
Files changed (69) hide show
  1. package/dist/constants/common.d.ts +6 -6
  2. package/dist/constants/enum.d.ts +2 -2
  3. package/dist/constants/index.d.ts +0 -1
  4. package/dist/constants/poolAddress.d.ts +2 -1
  5. package/dist/constants/queryKeys.d.ts +3 -4
  6. package/dist/index.d.ts +0 -1
  7. package/dist/index.js +2009 -1627
  8. package/dist/index.js.map +1 -1
  9. package/dist/index.mjs +2088 -1701
  10. package/dist/index.mjs.map +1 -1
  11. package/dist/models/scallop.d.ts +1 -2
  12. package/dist/models/scallopBuilder.d.ts +2 -1
  13. package/dist/models/scallopCache.d.ts +18 -12
  14. package/dist/models/scallopQuery.d.ts +95 -10
  15. package/dist/models/scallopUtils.d.ts +4 -4
  16. package/dist/queries/borrowIncentiveQuery.d.ts +6 -1
  17. package/dist/queries/coreQuery.d.ts +2 -0
  18. package/dist/queries/objectsQuery.d.ts +1 -2
  19. package/dist/queries/poolAddressesQuery.d.ts +4 -2
  20. package/dist/queries/portfolioQuery.d.ts +71 -5
  21. package/dist/queries/priceQuery.d.ts +4 -0
  22. package/dist/queries/sCoinQuery.d.ts +1 -1
  23. package/dist/types/builder/core.d.ts +3 -3
  24. package/dist/types/model.d.ts +8 -2
  25. package/dist/utils/index.d.ts +0 -2
  26. package/package.json +7 -7
  27. package/src/builders/borrowIncentiveBuilder.ts +11 -5
  28. package/src/builders/coreBuilder.ts +61 -32
  29. package/src/builders/loyaltyProgramBuilder.ts +3 -2
  30. package/src/builders/referralBuilder.ts +16 -6
  31. package/src/builders/sCoinBuilder.ts +6 -4
  32. package/src/builders/spoolBuilder.ts +14 -7
  33. package/src/builders/vescaBuilder.ts +13 -7
  34. package/src/constants/coinGecko.ts +2 -0
  35. package/src/constants/common.ts +7 -1
  36. package/src/constants/enum.ts +46 -20
  37. package/src/constants/index.ts +0 -1
  38. package/src/constants/poolAddress.ts +163 -41
  39. package/src/constants/pyth.ts +2 -0
  40. package/src/constants/queryKeys.ts +7 -9
  41. package/src/constants/testAddress.ts +24 -0
  42. package/src/index.ts +0 -1
  43. package/src/models/scallop.ts +9 -13
  44. package/src/models/scallopAddress.ts +2 -9
  45. package/src/models/scallopBuilder.ts +62 -8
  46. package/src/models/scallopCache.ts +220 -114
  47. package/src/models/scallopClient.ts +3 -6
  48. package/src/models/scallopIndexer.ts +1 -5
  49. package/src/models/scallopQuery.ts +53 -19
  50. package/src/models/scallopUtils.ts +9 -13
  51. package/src/queries/borrowIncentiveQuery.ts +6 -13
  52. package/src/queries/coreQuery.ts +62 -48
  53. package/src/queries/loyaltyProgramQuery.ts +1 -3
  54. package/src/queries/objectsQuery.ts +1 -3
  55. package/src/queries/poolAddressesQuery.ts +13 -10
  56. package/src/queries/portfolioQuery.ts +252 -20
  57. package/src/queries/priceQuery.ts +2 -7
  58. package/src/queries/sCoinQuery.ts +2 -2
  59. package/src/queries/spoolQuery.ts +21 -20
  60. package/src/queries/vescaQuery.ts +3 -7
  61. package/src/types/builder/core.ts +21 -3
  62. package/src/types/model.ts +13 -2
  63. package/src/utils/index.ts +0 -2
  64. package/src/utils/indexer.ts +3 -1
  65. package/src/utils/query.ts +2 -2
  66. package/dist/constants/tokenBucket.d.ts +0 -2
  67. package/dist/utils/tokenBucket.d.ts +0 -11
  68. package/src/constants/tokenBucket.ts +0 -2
  69. package/src/utils/tokenBucket.ts +0 -68
@@ -26,7 +26,12 @@ import type {
26
26
  ObligationBorrowIcentiveReward,
27
27
  SupportBorrowIncentiveRewardCoins,
28
28
  SupportAssetCoins,
29
+ MarketPools,
30
+ MarketCollaterals,
29
31
  } from '../types';
32
+ import { SuiObjectRef } from '@mysten/sui/client';
33
+ import { queryMultipleObjects } from './objectsQuery';
34
+ import { normalizeStructTag, SUI_TYPE_ARG } from '@scallop-io/sui-kit';
30
35
 
31
36
  /**
32
37
  * Get user lending infomation for specific pools.
@@ -41,6 +46,8 @@ export const getLendings = async (
41
46
  query: ScallopQuery,
42
47
  poolCoinNames: SupportPoolCoins[] = [...SUPPORT_POOLS],
43
48
  ownerAddress?: string,
49
+ marketPools?: MarketPools,
50
+ coinPrices?: CoinPrices,
44
51
  indexer: boolean = false
45
52
  ) => {
46
53
  const marketCoinNames = poolCoinNames.map((poolCoinName) =>
@@ -50,13 +57,15 @@ export const getLendings = async (
50
57
  (SUPPORT_SPOOLS as readonly SupportMarketCoins[]).includes(marketCoinName)
51
58
  ) as SupportStakeMarketCoins[];
52
59
 
53
- const coinPrices = await query.utils.getCoinPrices();
54
- const marketPools = (
55
- await query.getMarketPools(poolCoinNames, {
56
- indexer,
57
- coinPrices,
58
- })
59
- ).pools;
60
+ coinPrices = coinPrices ?? (await query.utils.getCoinPrices());
61
+ marketPools =
62
+ marketPools ??
63
+ (
64
+ await query.getMarketPools(poolCoinNames, {
65
+ indexer,
66
+ coinPrices,
67
+ })
68
+ ).pools;
60
69
 
61
70
  const spools = await query.getSpools(stakeMarketCoinNames, {
62
71
  indexer,
@@ -309,22 +318,34 @@ export const getLending = async (
309
318
  export const getObligationAccounts = async (
310
319
  query: ScallopQuery,
311
320
  ownerAddress?: string,
321
+ market?: {
322
+ pools: MarketPools;
323
+ collaterals: MarketCollaterals;
324
+ },
325
+ coinPrices?: CoinPrices,
312
326
  indexer: boolean = false
313
327
  ) => {
314
- const coinPrices = await query.utils.getCoinPrices();
315
- // const market = await query.queryMarket({ indexer, coinPrices });
316
- const market = await query.getMarketPools(undefined, { coinPrices, indexer });
328
+ market = market ?? (await query.getMarketPools(undefined, { indexer }));
329
+ coinPrices =
330
+ coinPrices ??
331
+ (await query.getAllCoinPrices({
332
+ marketPools: market.pools,
333
+ }));
317
334
  const [coinAmounts, obligations] = await Promise.all([
318
335
  query.getCoinAmounts(undefined, ownerAddress),
319
336
  query.getObligations(ownerAddress),
320
337
  ]);
321
338
 
339
+ const obligationObjects = await queryMultipleObjects(
340
+ query.cache,
341
+ obligations.map((obligation) => obligation.id)
342
+ );
322
343
  const obligationAccounts: ObligationAccounts = {};
323
344
  await Promise.allSettled(
324
- obligations.map(async (obligation) => {
345
+ obligations.map(async (obligation, idx) => {
325
346
  obligationAccounts[obligation.keyId] = await getObligationAccount(
326
347
  query,
327
- obligation.id,
348
+ obligationObjects[idx] ?? obligation.id,
328
349
  ownerAddress,
329
350
  indexer,
330
351
  market,
@@ -341,13 +362,13 @@ export const getObligationAccounts = async (
341
362
  * Get obligation account data.
342
363
  *
343
364
  * @param query - The Scallop query instance.
344
- * @param obligationId - The obligation id.
365
+ * @param obligation - The obligation id.
345
366
  * @param indexer - Whether to use indexer.
346
367
  * @return Obligation account data.
347
368
  */
348
369
  export const getObligationAccount = async (
349
370
  query: ScallopQuery,
350
- obligationId: string,
371
+ obligation: string | SuiObjectRef,
351
372
  ownerAddress?: string,
352
373
  indexer: boolean = false,
353
374
  market?: Market,
@@ -361,7 +382,6 @@ export const getObligationAccount = async (
361
382
  ...SUPPORT_COLLATERALS,
362
383
  ] as SupportCollateralCoins[];
363
384
 
364
- // market = market ?? (await query.queryMarket({ indexer }));
365
385
  market = market ?? (await query.getMarketPools(undefined, { indexer }));
366
386
  coinPrices =
367
387
  coinPrices ?? (await query.getAllCoinPrices({ marketPools: market.pools }));
@@ -370,13 +390,12 @@ export const getObligationAccount = async (
370
390
 
371
391
  const [obligationQuery, borrowIncentivePools, borrowIncentiveAccounts] =
372
392
  await Promise.all([
373
- query.queryObligation(obligationId),
393
+ query.queryObligation(obligation),
374
394
  query.getBorrowIncentivePools(undefined, {
375
395
  coinPrices,
376
- indexer,
377
396
  marketPools: market.pools,
378
397
  }),
379
- query.getBorrowIncentiveAccounts(obligationId),
398
+ query.getBorrowIncentiveAccounts(obligation),
380
399
  ]);
381
400
 
382
401
  const collaterals: ObligationAccount['collaterals'] = {};
@@ -656,7 +675,8 @@ export const getObligationAccount = async (
656
675
  : BigNumber(0);
657
676
 
658
677
  const obligationAccount: ObligationAccount = {
659
- obligationId: obligationId,
678
+ obligationId:
679
+ typeof obligation === 'string' ? obligation : obligation.objectId,
660
680
  // Deposited collateral value (collateral balance)
661
681
  totalDepositedValue: totalDepositedValue.toNumber(),
662
682
  // Borrowed debt value (liabilities balance)
@@ -789,7 +809,6 @@ export const getTotalValueLocked = async (
789
809
  query: ScallopQuery,
790
810
  indexer: boolean = false
791
811
  ) => {
792
- // const market = await query.queryMarket({ indexer });
793
812
  const market = await query.getMarketPools(undefined, { indexer });
794
813
 
795
814
  let supplyValue = BigNumber(0);
@@ -832,3 +851,216 @@ export const getTotalValueLocked = async (
832
851
 
833
852
  return tvl;
834
853
  };
854
+
855
+ /**
856
+ * Get user portfolio by wallet address
857
+ */
858
+ export const getUserPortfolio = async (
859
+ query: ScallopQuery,
860
+ walletAddress: string,
861
+ indexer: boolean = false
862
+ ) => {
863
+ const coinPrices = await query.utils.getCoinPrices();
864
+ const market = await query.getMarketPools(undefined, { indexer, coinPrices });
865
+
866
+ const [lendings, obligationAccounts, borrowIncentivePools, veScas] =
867
+ await Promise.all([
868
+ query.getLendings(undefined, walletAddress, {
869
+ indexer,
870
+ marketPools: market.pools,
871
+ coinPrices,
872
+ }),
873
+ query.getObligationAccounts(walletAddress, {
874
+ indexer,
875
+ market: market,
876
+ coinPrices,
877
+ }),
878
+ query.getBorrowIncentivePools(undefined, {
879
+ marketPools: market.pools,
880
+ coinPrices,
881
+ }),
882
+ query.getVeScas({ walletAddress, excludeEmpty: true }),
883
+ ]);
884
+
885
+ // get pending rewards (spool and borrow incentive)
886
+ const parsedLendings = Object.values(lendings)
887
+ .filter((t) => t.availableWithdrawCoin > 0)
888
+ .map((lending) => ({
889
+ suppliedCoin: lending.availableWithdrawCoin,
890
+ suppliedValue: lending.suppliedValue,
891
+ stakedCoin: lending.availableUnstakeCoin,
892
+ coinName: lending.coinName,
893
+ symbol: lending.symbol,
894
+ coinType: lending.coinType,
895
+ coinPrice: lending.coinPrice,
896
+ coinDecimals: lending.coinDecimal,
897
+ supplyApr: lending.supplyApr,
898
+ supplyApy: lending.supplyApy,
899
+ incentiveApr: isFinite(lending.rewardApr) ? lending.rewardApr : 0,
900
+ }));
901
+
902
+ const parsedObligationAccounts = Object.values(obligationAccounts)
903
+ .filter(
904
+ (t): t is NonNullable<typeof t> =>
905
+ !!t && t.totalBorrowedValueWithWeight > 0
906
+ )
907
+ .map((obligationAccount) => {
908
+ return {
909
+ obligationId: obligationAccount.obligationId,
910
+ totalDebtsInUsd: obligationAccount.totalBorrowedValueWithWeight,
911
+ totalCollateralInUsd: obligationAccount.totalDepositedValue,
912
+ riskLevel: obligationAccount.totalRiskLevel,
913
+ availableCollateralInUsd:
914
+ obligationAccount.totalAvailableCollateralValue,
915
+ totalUnhealthyCollateralInUsd:
916
+ obligationAccount.totalUnhealthyCollateralValue,
917
+ borrowedPools: Object.values(obligationAccount.debts)
918
+ .filter((debt) => debt.borrowedCoin > 0)
919
+ .map((debt) => ({
920
+ coinName: debt.coinName,
921
+ symbol: debt.symbol,
922
+ coinDecimals: debt.coinDecimal,
923
+ coinType: debt.coinType,
924
+ coinPrice: debt.coinPrice,
925
+ borrowedCoin: debt.borrowedCoin,
926
+ borrowedValueInUsd: debt.borrowedValueWithWeight,
927
+ borrowApr: market.pools[debt.coinName]?.borrowApr,
928
+ borrowApy: market.pools[debt.coinName]?.borrowApy,
929
+ incentiveInfos: Object.values(
930
+ borrowIncentivePools[debt.coinName]?.points ?? {}
931
+ )
932
+ .filter((t) => isFinite(t.rewardApr))
933
+ .map((t) => ({
934
+ coinName: t.coinName,
935
+ symbol: t.symbol,
936
+ coinType: t.coinType,
937
+ incentiveApr: t.rewardApr,
938
+ })),
939
+ })),
940
+ };
941
+ });
942
+
943
+ const pendingLendingRewards = Object.values(lendings).reduce(
944
+ (acc, reward) => {
945
+ if (reward.availableClaimCoin === 0) return acc;
946
+ if (!acc[reward.symbol]) {
947
+ acc[reward.symbol] = {
948
+ symbol: reward.symbol,
949
+ coinType: normalizeStructTag(SUI_TYPE_ARG), // @TODO: for now lending reward is all in SUI
950
+ coinPrice: reward.coinPrice,
951
+ pendingRewardInCoin: reward.availableClaimCoin,
952
+ };
953
+ } else {
954
+ acc[reward.symbol].pendingRewardInCoin += reward.availableClaimCoin;
955
+ }
956
+ return acc;
957
+ },
958
+ {} as Record<
959
+ string,
960
+ {
961
+ coinType: string;
962
+ symbol: string;
963
+ coinPrice: number;
964
+ pendingRewardInCoin: number;
965
+ }
966
+ >
967
+ );
968
+
969
+ const pendingBorrowIncentiveRewards = Object.values(obligationAccounts)
970
+ .filter((t): t is NonNullable<typeof t> => !!t)
971
+ .reduce(
972
+ (acc, curr) => {
973
+ Object.values(curr.borrowIncentives).forEach((incentive) => {
974
+ incentive.rewards.forEach((reward) => {
975
+ if (reward.availableClaimCoin === 0) return acc;
976
+ if (!acc[reward.coinName]) {
977
+ acc[reward.coinName] = {
978
+ symbol: reward.symbol,
979
+ coinType: reward.coinType,
980
+ coinPrice: reward.coinPrice,
981
+ pendingRewardInCoin: reward.availableClaimCoin,
982
+ };
983
+ } else {
984
+ acc[reward.coinName].pendingRewardInCoin +=
985
+ reward.availableClaimCoin;
986
+ }
987
+ });
988
+ });
989
+ return acc;
990
+ },
991
+ {} as Record<
992
+ string,
993
+ {
994
+ coinType: string;
995
+ symbol: string;
996
+ coinPrice: number;
997
+ pendingRewardInCoin: number;
998
+ }
999
+ >
1000
+ );
1001
+
1002
+ const parsedVeScas = veScas.map(
1003
+ ({ keyId, lockedScaCoin, currentVeScaBalance, unlockAt }) => ({
1004
+ veScaKey: keyId,
1005
+ coinPrice: coinPrices.sca ?? 0,
1006
+ lockedScaInCoin: lockedScaCoin,
1007
+ lockedScaInUsd: lockedScaCoin * (coinPrices.sca ?? 0),
1008
+ currentVeScaBalance,
1009
+ remainingLockPeriodInDays:
1010
+ unlockAt - Date.now() > 0 ? (unlockAt - Date.now()) / 86400000 : 0,
1011
+ unlockAt,
1012
+ })
1013
+ );
1014
+
1015
+ return {
1016
+ totalSupplyValue: parsedLendings.reduce((acc, curr) => {
1017
+ acc += curr.suppliedValue;
1018
+ return acc;
1019
+ }, 0),
1020
+ ...parsedObligationAccounts.reduce(
1021
+ (acc, curr) => {
1022
+ acc.totalDebtValue += curr.totalDebtsInUsd;
1023
+ acc.totalCollateralValue += curr.totalCollateralInUsd;
1024
+ return acc;
1025
+ },
1026
+ {
1027
+ totalDebtValue: 0,
1028
+ totalCollateralValue: 0,
1029
+ } as {
1030
+ totalDebtValue: number;
1031
+ totalCollateralValue: number;
1032
+ }
1033
+ ),
1034
+ totalLockedScaValue: parsedVeScas.reduce((acc, curr) => {
1035
+ acc += curr.lockedScaInUsd;
1036
+ return acc;
1037
+ }, 0),
1038
+ lendings: parsedLendings,
1039
+ borrowings: parsedObligationAccounts,
1040
+ pendingRewards: {
1041
+ lendings: Object.entries(pendingLendingRewards).reduce(
1042
+ (acc, [key, value]) => {
1043
+ acc.push({
1044
+ ...value,
1045
+ coinName: key,
1046
+ pendingRewardInUsd: value.coinPrice * value.pendingRewardInCoin,
1047
+ });
1048
+ return acc;
1049
+ },
1050
+ [] as any
1051
+ ),
1052
+ borrowIncentives: Object.entries(pendingBorrowIncentiveRewards).reduce(
1053
+ (acc, [key, value]) => {
1054
+ acc.push({
1055
+ coinName: key,
1056
+ ...value,
1057
+ pendingRewardInUsd: value.coinPrice * value.pendingRewardInCoin,
1058
+ });
1059
+ return acc;
1060
+ },
1061
+ [] as any
1062
+ ),
1063
+ },
1064
+ veScas: parsedVeScas,
1065
+ };
1066
+ };
@@ -31,11 +31,7 @@ export const getPythPrice = async (
31
31
  );
32
32
  priceFeedObject =
33
33
  priceFeedObject ||
34
- (
35
- await address.cache.queryGetObject(pythFeedObjectId, {
36
- showContent: true,
37
- })
38
- )?.data;
34
+ (await address.cache.queryGetObject(pythFeedObjectId))?.data;
39
35
 
40
36
  if (priceFeedObject) {
41
37
  const priceFeedPoolObject = priceFeedObject;
@@ -99,8 +95,7 @@ export const getPythPrices = async (
99
95
 
100
96
  // Fetch multiple objects at once to save rpc calls
101
97
  const priceFeedObjects = await address.cache.queryGetObjects(
102
- Object.keys(pythPriceFeedIds),
103
- { showContent: true }
98
+ Object.keys(pythPriceFeedIds)
104
99
  );
105
100
 
106
101
  const assetToPriceFeedMapping = priceFeedObjects.reduce(
@@ -95,11 +95,11 @@ export const getSCoinAmount = async (
95
95
  ) => {
96
96
  const owner = ownerAddress || utils.suiKit.currentAddress();
97
97
  const sCoinType = utils.parseSCoinType(sCoinName);
98
- const amount = await utils.cache.queryGetCoinBalance({
98
+ const coinBalance = await utils.cache.queryGetCoinBalance({
99
99
  owner,
100
100
  coinType: sCoinType,
101
101
  });
102
- return BigNumber(amount).toNumber();
102
+ return BigNumber(coinBalance?.totalBalance ?? '0').toNumber();
103
103
  };
104
104
 
105
105
  const isSupportStakeCoins = (value: string): value is SupportSCoin => {
@@ -58,24 +58,33 @@ const queryRequiredSpoolObjects = async (
58
58
  // Map the results back to poolCoinNames
59
59
  const mapObjects = (
60
60
  tasks: { poolCoinName: string; [key: string]: string | undefined }[],
61
- fetchedObjects: SuiObjectData[]
61
+ fetchedObjects: SuiObjectData[],
62
+ keyValue: string
62
63
  ) => {
63
64
  const resultMap: Record<string, SuiObjectData> = {};
64
- let fetchedIndex = 0;
65
+ const fetchedObjectMap = fetchedObjects.reduce(
66
+ (acc, obj) => {
67
+ acc[obj.objectId] = obj;
68
+ return acc;
69
+ },
70
+ {} as Record<string, SuiObjectData>
71
+ );
65
72
 
66
73
  for (const task of tasks) {
67
- const key = task[Object.keys(task)[1]]; // current object key being queried
68
- if (key) {
69
- resultMap[task.poolCoinName] = fetchedObjects[fetchedIndex];
70
- fetchedIndex++;
74
+ if (task[keyValue]) {
75
+ resultMap[task.poolCoinName] = fetchedObjectMap[task[keyValue]];
71
76
  }
72
77
  }
73
78
  return resultMap;
74
79
  };
75
80
 
76
- const spoolMap = mapObjects(tasks, spoolObjects);
77
- const spoolRewardMap = mapObjects(tasks, spoolRewardObjects);
78
- const sCoinTreasuryMap = mapObjects(tasks, sCoinTreasuryObjects);
81
+ const spoolMap = mapObjects(tasks, spoolObjects, 'spool');
82
+ const spoolRewardMap = mapObjects(tasks, spoolRewardObjects, 'spoolReward');
83
+ const sCoinTreasuryMap = mapObjects(
84
+ tasks,
85
+ sCoinTreasuryObjects,
86
+ 'sCoinTreasury'
87
+ );
79
88
 
80
89
  // Construct the final requiredObjects result
81
90
  return stakePoolCoinNames.reduce(
@@ -444,10 +453,7 @@ export const getStakePool = async (
444
453
  ) => {
445
454
  const poolId = utils.address.get(`spool.pools.${marketCoinName}.id`);
446
455
  let stakePool: StakePool | undefined = undefined;
447
- const stakePoolObjectResponse = await utils.cache.queryGetObject(poolId, {
448
- showContent: true,
449
- showType: true,
450
- });
456
+ const stakePoolObjectResponse = await utils.cache.queryGetObject(poolId);
451
457
  if (stakePoolObjectResponse?.data) {
452
458
  const stakePoolObject = stakePoolObjectResponse.data;
453
459
  const id = stakePoolObject.objectId;
@@ -506,13 +512,8 @@ export const getStakeRewardPool = async (
506
512
  `spool.pools.${marketCoinName}.rewardPoolId`
507
513
  );
508
514
  let stakeRewardPool: StakeRewardPool | undefined = undefined;
509
- const stakeRewardPoolObjectResponse = await utils.cache.queryGetObject(
510
- poolId,
511
- {
512
- showContent: true,
513
- showType: true,
514
- }
515
- );
515
+ const stakeRewardPoolObjectResponse =
516
+ await utils.cache.queryGetObject(poolId);
516
517
 
517
518
  if (stakeRewardPoolObjectResponse?.data) {
518
519
  const stakeRewardPoolObject = stakeRewardPoolObjectResponse.data;
@@ -195,8 +195,7 @@ const getTotalVeScaTreasuryAmount = async (
195
195
  const resolvedRefreshArgs = await Promise.all(
196
196
  refreshArgs.map(async (arg) => {
197
197
  if (typeof arg === 'string') {
198
- return (await utils.cache.queryGetObject(arg, { showContent: true }))
199
- ?.data;
198
+ return (await utils.cache.queryGetObject(arg))?.data;
200
199
  }
201
200
  return arg;
202
201
  })
@@ -205,8 +204,7 @@ const getTotalVeScaTreasuryAmount = async (
205
204
  const resolvedVeScaAmountArgs = await Promise.all(
206
205
  veScaAmountArgs.map(async (arg) => {
207
206
  if (typeof arg === 'string') {
208
- return (await utils.cache.queryGetObject(arg, { showContent: true }))
209
- ?.data;
207
+ return (await utils.cache.queryGetObject(arg))?.data;
210
208
  }
211
209
  return arg;
212
210
  })
@@ -254,9 +252,7 @@ export const getVeScaTreasuryInfo = async (
254
252
  utils: ScallopUtils
255
253
  ): Promise<VeScaTreasuryInfo | null> => {
256
254
  const veScaTreasuryId = utils.address.get('vesca.treasury');
257
- const veScaTreasury = await utils.cache.queryGetObject(veScaTreasuryId, {
258
- showContent: true,
259
- });
255
+ const veScaTreasury = await utils.cache.queryGetObject(veScaTreasuryId);
260
256
 
261
257
  if (!veScaTreasury || veScaTreasury.data?.content?.dataType !== 'moveObject')
262
258
  return null;
@@ -26,41 +26,54 @@ type ObligationKey = NestedResult;
26
26
  type ObligationHotPotato = NestedResult;
27
27
 
28
28
  export type CoreNormalMethods = {
29
+ // openObligation: () => Promise<
29
30
  openObligation: () => [Obligation, ObligationKey, ObligationHotPotato];
30
31
  returnObligation: (
31
32
  obligation: SuiObjectArg,
32
33
  obligationHotPotato: SuiObjectArg
34
+ // ) => Promise<void>;
33
35
  ) => void;
36
+ // openObligationEntry: () => Promise<void>;
34
37
  openObligationEntry: () => void;
35
38
  addCollateral: (
36
39
  obligation: SuiObjectArg,
37
40
  coin: SuiObjectArg,
38
41
  collateralCoinName: SupportCollateralCoins
42
+ // ) => Promise<void>;
39
43
  ) => void;
40
44
  takeCollateral: (
41
45
  obligation: SuiObjectArg,
42
46
  obligationKey: SuiObjectArg,
43
47
  amount: number,
44
48
  collateralCoinName: SupportCollateralCoins
49
+ // ) => Promise<TransactionResult>;
45
50
  ) => TransactionResult;
46
51
  deposit: (
47
52
  coin: SuiObjectArg,
48
53
  poolCoinName: SupportPoolCoins
54
+ // ) => Promise<TransactionResult>;
55
+ ) => TransactionResult;
56
+ depositEntry: (
57
+ coin: SuiObjectArg,
58
+ poolCoinName: SupportPoolCoins
59
+ // ) => Promise<TransactionResult>;
49
60
  ) => TransactionResult;
50
- depositEntry: (coin: SuiObjectArg, poolCoinName: SupportPoolCoins) => void;
51
61
  withdraw: (
52
62
  marketCoin: SuiObjectArg,
53
63
  poolCoinName: SupportPoolCoins
64
+ // ) => Promise<TransactionResult>;
54
65
  ) => TransactionResult;
55
66
  withdrawEntry: (
56
67
  marketCoin: SuiObjectArg,
57
68
  poolCoinName: SupportPoolCoins
58
- ) => void;
69
+ // ) => Promise<TransactionResult>;
70
+ ) => TransactionResult;
59
71
  borrow: (
60
72
  obligation: SuiObjectArg,
61
73
  obligationKey: SuiObjectArg,
62
74
  amount: number,
63
75
  poolCoinName: SupportPoolCoins
76
+ // ) => Promise<TransactionResult>;
64
77
  ) => TransactionResult;
65
78
  borrowWithReferral: (
66
79
  obligation: SuiObjectArg,
@@ -68,26 +81,31 @@ export type CoreNormalMethods = {
68
81
  borrowReferral: SuiObjectArg,
69
82
  amount: number | SuiTxArg,
70
83
  poolCoinName: SupportPoolCoins
84
+ // ) => Promise<TransactionResult>;
71
85
  ) => TransactionResult;
72
86
  borrowEntry: (
73
87
  obligation: SuiObjectArg,
74
88
  obligationKey: SuiObjectArg,
75
89
  amount: number,
76
90
  poolCoinName: SupportPoolCoins
77
- ) => void;
91
+ // ) => Promise<TransactionResult>;
92
+ ) => TransactionResult;
78
93
  repay: (
79
94
  obligation: SuiObjectArg,
80
95
  coin: SuiObjectArg,
81
96
  poolCoinName: SupportPoolCoins
97
+ // ) => Promise<void>;
82
98
  ) => void;
83
99
  borrowFlashLoan: (
84
100
  amount: number | SuiTxArg,
85
101
  poolCoinName: SupportPoolCoins
102
+ // ) => Promise<TransactionResult>;
86
103
  ) => TransactionResult;
87
104
  repayFlashLoan: (
88
105
  coin: SuiObjectArg,
89
106
  loan: SuiObjectArg,
90
107
  poolCoinName: SupportPoolCoins
108
+ // ) => Promise<void>;
91
109
  ) => void;
92
110
  };
93
111
 
@@ -10,6 +10,7 @@ import type {
10
10
  } from '../models';
11
11
  import { ScallopCache } from 'src/models/scallopCache';
12
12
  import { AddressesInterface } from './address';
13
+ import { QueryClient, QueryClientConfig } from '@tanstack/query-core';
13
14
 
14
15
  export type ScallopClientFnReturnType<T extends boolean> = T extends true
15
16
  ? SuiTransactionBlockResponse
@@ -26,7 +27,9 @@ export type ScallopBaseInstanceParams = {
26
27
  suiKit?: SuiKit;
27
28
  };
28
29
 
29
- export type ScallopCacheInstanceParams = ScallopBaseInstanceParams;
30
+ export type ScallopCacheInstanceParams = ScallopBaseInstanceParams & {
31
+ queryClient?: QueryClient;
32
+ };
30
33
 
31
34
  export type ScallopAddressInstanceParams = ScallopBaseInstanceParams & {
32
35
  cache?: ScallopCache;
@@ -69,7 +72,8 @@ export type ScallopParams = {
69
72
  export type ScallopClientParams = ScallopParams &
70
73
  ScallopBuilderParams &
71
74
  ScallopQueryParams &
72
- ScallopUtilsParams;
75
+ ScallopUtilsParams &
76
+ ScallopCacheParams;
73
77
 
74
78
  export type ScallopBuilderParams = ScallopParams & {
75
79
  pythEndpoints?: string[];
@@ -81,3 +85,10 @@ export type ScallopQueryParams = ScallopParams & ScallopUtilsParams;
81
85
  export type ScallopUtilsParams = ScallopParams & {
82
86
  pythEndpoints?: string[];
83
87
  };
88
+
89
+ export type ScallopCacheParams = Omit<
90
+ ScallopParams,
91
+ 'addressId' | 'forceAddressesInterface'
92
+ > & {
93
+ cacheOptions?: QueryClientConfig;
94
+ };
@@ -1,7 +1,5 @@
1
1
  export * from './builder';
2
2
  export * from './query';
3
3
  export * from './util';
4
- export * from './tokenBucket';
5
4
  export * from './indexer';
6
5
  export * from './core';
7
- export * from './tokenBucket';
@@ -17,7 +17,9 @@ export async function callMethodWithIndexerFallback(
17
17
  try {
18
18
  return await method.apply(context, args);
19
19
  } catch (e: any) {
20
- console.warn(`Indexer requests failed: ${e}. Retrying without indexer..`);
20
+ console.warn(
21
+ `Indexer requests failed: ${e.message}. Retrying without indexer..`
22
+ );
21
23
  return await method.apply(context, [
22
24
  ...args.slice(0, -1),
23
25
  {
@@ -167,10 +167,10 @@ export const calculateMarketPoolData = (
167
167
  conversionRate: conversionRate.toNumber(),
168
168
  isIsolated: parsedMarketPoolData.isIsolated,
169
169
  maxSupplyCoin: BigNumber(parsedMarketPoolData.supplyLimit)
170
- .shiftedBy(coinDecimal)
170
+ .shiftedBy(-coinDecimal)
171
171
  .toNumber(),
172
172
  maxBorrowCoin: BigNumber(parsedMarketPoolData.borrowLimit)
173
- .shiftedBy(coinDecimal)
173
+ .shiftedBy(-coinDecimal)
174
174
  .toNumber(),
175
175
  };
176
176
  };
@@ -1,2 +0,0 @@
1
- export declare const DEFAULT_TOKENS_PER_INTERVAL = 10;
2
- export declare const DEFAULT_INTERVAL_IN_MS = 250;
@@ -1,11 +0,0 @@
1
- declare class TokenBucket {
2
- private tokensPerInterval;
3
- private interval;
4
- private tokens;
5
- private lastRefill;
6
- constructor(tokensPerInterval: number, intervalInMs: number);
7
- refill(): void;
8
- removeTokens(count: number): boolean;
9
- }
10
- declare const callWithRateLimit: <T>(tokenBucket: TokenBucket, fn: () => Promise<T>, retryDelayInMs?: number, maxRetries?: number, backoffFactor?: number) => Promise<T | null>;
11
- export { TokenBucket, callWithRateLimit };
@@ -1,2 +0,0 @@
1
- export const DEFAULT_TOKENS_PER_INTERVAL = 10;
2
- export const DEFAULT_INTERVAL_IN_MS = 250;