@scallop-io/sui-scallop-sdk 1.4.1-alpha.1 → 1.4.2-rc.1

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 (88) hide show
  1. package/dist/constants/common.d.ts +4 -4
  2. package/dist/constants/enum.d.ts +2 -2
  3. package/dist/constants/poolAddress.d.ts +16 -4
  4. package/dist/constants/queryKeys.d.ts +2 -2
  5. package/dist/constants/tokenBucket.d.ts +2 -2
  6. package/dist/index.d.ts +1 -0
  7. package/dist/index.js +1314 -653
  8. package/dist/index.js.map +1 -1
  9. package/dist/index.mjs +1269 -609
  10. package/dist/index.mjs.map +1 -1
  11. package/dist/models/scallopBuilder.d.ts +2 -1
  12. package/dist/models/scallopCache.d.ts +2 -0
  13. package/dist/models/scallopQuery.d.ts +46 -20
  14. package/dist/models/scallopUtils.d.ts +5 -3
  15. package/dist/queries/borrowIncentiveQuery.d.ts +12 -0
  16. package/dist/queries/coreQuery.d.ts +18 -17
  17. package/dist/queries/index.d.ts +2 -0
  18. package/dist/queries/isolatedAssetQuery.d.ts +2 -2
  19. package/dist/queries/objectsQuery.d.ts +3 -0
  20. package/dist/queries/poolAddressesQuery.d.ts +18 -0
  21. package/dist/queries/portfolioQuery.d.ts +2 -0
  22. package/dist/queries/priceQuery.d.ts +4 -0
  23. package/dist/queries/sCoinQuery.d.ts +1 -1
  24. package/dist/queries/spoolQuery.d.ts +6 -2
  25. package/dist/test.d.ts +1 -0
  26. package/dist/types/builder/borrowIncentive.d.ts +5 -5
  27. package/dist/types/builder/core.d.ts +20 -16
  28. package/dist/types/builder/loyaltyProgram.d.ts +1 -1
  29. package/dist/types/builder/referral.d.ts +4 -4
  30. package/dist/types/builder/sCoin.d.ts +2 -2
  31. package/dist/types/builder/spool.d.ts +4 -4
  32. package/dist/types/builder/vesca.d.ts +6 -6
  33. package/dist/types/query/core.d.ts +22 -5
  34. package/dist/types/query/spool.d.ts +20 -0
  35. package/dist/types/utils.d.ts +7 -2
  36. package/dist/utils/core.d.ts +2 -0
  37. package/dist/utils/index.d.ts +2 -0
  38. package/dist/utils/query.d.ts +1 -1
  39. package/dist/utils/util.d.ts +1 -0
  40. package/package.json +7 -7
  41. package/src/builders/borrowIncentiveBuilder.ts +28 -15
  42. package/src/builders/coreBuilder.ts +76 -49
  43. package/src/builders/loyaltyProgramBuilder.ts +4 -3
  44. package/src/builders/referralBuilder.ts +23 -10
  45. package/src/builders/sCoinBuilder.ts +8 -6
  46. package/src/builders/spoolBuilder.ts +21 -14
  47. package/src/builders/vescaBuilder.ts +23 -13
  48. package/src/constants/coinGecko.ts +2 -3
  49. package/src/constants/common.ts +5 -19
  50. package/src/constants/enum.ts +20 -35
  51. package/src/constants/poolAddress.ts +344 -19
  52. package/src/constants/pyth.ts +2 -3
  53. package/src/constants/queryKeys.ts +9 -5
  54. package/src/constants/testAddress.ts +42 -0
  55. package/src/constants/tokenBucket.ts +2 -2
  56. package/src/index.ts +1 -0
  57. package/src/models/scallopBuilder.ts +59 -2
  58. package/src/models/scallopCache.ts +171 -19
  59. package/src/models/scallopClient.ts +16 -10
  60. package/src/models/scallopQuery.ts +36 -28
  61. package/src/models/scallopUtils.ts +11 -4
  62. package/src/queries/borrowIncentiveQuery.ts +6 -8
  63. package/src/queries/borrowLimitQuery.ts +3 -3
  64. package/src/queries/coreQuery.ts +408 -258
  65. package/src/queries/index.ts +2 -0
  66. package/src/queries/isolatedAssetQuery.ts +39 -34
  67. package/src/queries/objectsQuery.ts +20 -0
  68. package/src/queries/poolAddressesQuery.ts +146 -0
  69. package/src/queries/portfolioQuery.ts +31 -13
  70. package/src/queries/priceQuery.ts +3 -1
  71. package/src/queries/spoolQuery.ts +189 -122
  72. package/src/queries/supplyLimitQuery.ts +2 -3
  73. package/src/test.ts +14 -17
  74. package/src/types/builder/borrowIncentive.ts +8 -5
  75. package/src/types/builder/core.ts +23 -17
  76. package/src/types/builder/loyaltyProgram.ts +1 -1
  77. package/src/types/builder/referral.ts +6 -4
  78. package/src/types/builder/sCoin.ts +2 -2
  79. package/src/types/builder/spool.ts +4 -4
  80. package/src/types/builder/vesca.ts +9 -6
  81. package/src/types/query/core.ts +21 -5
  82. package/src/types/query/spool.ts +21 -0
  83. package/src/types/utils.ts +8 -3
  84. package/src/utils/core.ts +18 -0
  85. package/src/utils/index.ts +2 -0
  86. package/src/utils/query.ts +21 -5
  87. package/src/utils/tokenBucket.ts +9 -29
  88. package/src/utils/util.ts +8 -0
@@ -3,6 +3,7 @@ import {
3
3
  SuiObjectArg,
4
4
  SuiTxBlock,
5
5
  normalizeStructTag,
6
+ parseStructTag,
6
7
  } from '@scallop-io/sui-kit';
7
8
  import { SuiKit } from '@scallop-io/sui-kit';
8
9
  import type {
@@ -106,6 +107,12 @@ export class ScallopCache {
106
107
  );
107
108
  }
108
109
 
110
+ private retryFn(errCount: number, e: any) {
111
+ if (errCount === 5) return false;
112
+ if (e.status === 429) return true;
113
+ return false;
114
+ }
115
+
109
116
  /**
110
117
  * @description Provides cache for inspectTxn of the SuiKit.
111
118
  * @param QueryInspectTxnParams
@@ -119,19 +126,75 @@ export class ScallopCache {
119
126
  }: QueryInspectTxnParams): Promise<DevInspectResults | null> {
120
127
  const txBlock = new SuiTxBlock();
121
128
 
122
- txBlock.moveCall(queryTarget, args, typeArgs);
129
+ const resolvedQueryTarget =
130
+ await this.queryGetNormalizedMoveFunction(queryTarget);
131
+ if (!resolvedQueryTarget) throw new Error('Invalid query target');
132
+
133
+ const { parameters } = resolvedQueryTarget;
134
+
135
+ const resolvedArgs = await Promise.all(
136
+ (args ?? []).map(async (arg, idx) => {
137
+ if (typeof arg !== 'string') return arg;
138
+
139
+ const cachedData = (await this.queryGetObject(arg))?.data;
140
+ if (!cachedData) return arg;
141
+
142
+ const owner = cachedData.owner;
143
+ if (!owner || typeof owner !== 'object' || !('Shared' in owner))
144
+ return {
145
+ objectId: cachedData.objectId,
146
+ version: cachedData.version,
147
+ digest: cachedData.digest,
148
+ };
149
+
150
+ const parameter = parameters[idx];
151
+ if (
152
+ typeof parameter !== 'object' ||
153
+ !('MutableReference' in parameter || 'Reference' in parameter)
154
+ )
155
+ return arg;
156
+
157
+ return {
158
+ objectId: cachedData.objectId,
159
+ initialSharedVersion: owner.Shared.initial_shared_version,
160
+ mutable: 'MutableReference' in parameter,
161
+ };
162
+ })
163
+ );
164
+ txBlock.moveCall(queryTarget, resolvedArgs, typeArgs);
123
165
 
124
166
  const query = await this.queryClient.fetchQuery({
167
+ retry: this.retryFn,
168
+ retryDelay: 1000,
125
169
  queryKey: queryKeys.rpc.getInspectTxn(queryTarget, args, typeArgs),
126
170
  queryFn: async () => {
127
- return await callWithRateLimit(this.tokenBucket, () =>
128
- this.suiKit.inspectTxn(txBlock)
171
+ return await callWithRateLimit(
172
+ this.tokenBucket,
173
+ async () => await this.suiKit.inspectTxn(txBlock)
129
174
  );
130
175
  },
131
176
  });
132
177
  return query;
133
178
  }
134
179
 
180
+ public async queryGetNormalizedMoveFunction(target: string) {
181
+ const { address, module, name } = parseStructTag(target);
182
+ return this.queryClient.fetchQuery({
183
+ queryKey: queryKeys.rpc.getNormalizedMoveFunction(target),
184
+ queryFn: async () => {
185
+ return await callWithRateLimit(
186
+ this.tokenBucket,
187
+ async () =>
188
+ await this.suiKit.client().getNormalizedMoveFunction({
189
+ package: address,
190
+ module,
191
+ function: name,
192
+ })
193
+ );
194
+ },
195
+ });
196
+ }
197
+
135
198
  /**
136
199
  * @description Provides cache for getObject of the SuiKit.
137
200
  * @param objectId
@@ -141,15 +204,24 @@ export class ScallopCache {
141
204
  public async queryGetObject(
142
205
  objectId: string,
143
206
  options?: SuiObjectDataOptions
144
- ): Promise<SuiObjectResponse | null> {
207
+ ) {
208
+ options = {
209
+ ...options,
210
+ showOwner: true,
211
+ showContent: true,
212
+ };
145
213
  return this.queryClient.fetchQuery({
146
- queryKey: queryKeys.rpc.getObject(objectId, this.walletAddress, options),
214
+ retry: this.retryFn,
215
+ retryDelay: 1000,
216
+ queryKey: queryKeys.rpc.getObject(objectId, options),
147
217
  queryFn: async () => {
148
- return await callWithRateLimit(this.tokenBucket, () =>
149
- this.client.getObject({
150
- id: objectId,
151
- options,
152
- })
218
+ return await callWithRateLimit(
219
+ this.tokenBucket,
220
+ async () =>
221
+ await this.client.getObject({
222
+ id: objectId,
223
+ options,
224
+ })
153
225
  );
154
226
  },
155
227
  });
@@ -170,15 +242,36 @@ export class ScallopCache {
170
242
  // objectIds.sort();
171
243
 
172
244
  return this.queryClient.fetchQuery({
245
+ retry: this.retryFn,
246
+ retryDelay: 1000,
173
247
  queryKey: queryKeys.rpc.getObjects(
174
248
  objectIds,
175
249
  this.walletAddress,
176
250
  options
177
251
  ),
178
252
  queryFn: async () => {
179
- return await callWithRateLimit(this.tokenBucket, () =>
180
- this.suiKit.getObjects(objectIds, options)
253
+ const results = await callWithRateLimit(
254
+ this.tokenBucket,
255
+ async () => await this.suiKit.getObjects(objectIds, options)
181
256
  );
257
+ if (results) {
258
+ results.forEach((result) => {
259
+ this.queryClient.setQueriesData(
260
+ {
261
+ exact: false,
262
+ queryKey: queryKeys.rpc.getObject(result.objectId, options),
263
+ },
264
+ {
265
+ data: result,
266
+ error: null,
267
+ },
268
+ {
269
+ updatedAt: Date.now(),
270
+ }
271
+ );
272
+ });
273
+ }
274
+ return results;
182
275
  },
183
276
  });
184
277
  }
@@ -189,12 +282,44 @@ export class ScallopCache {
189
282
  * @returns Promise<PaginatedObjectsResponse>
190
283
  */
191
284
  public async queryGetOwnedObjects(input: GetOwnedObjectsParams) {
285
+ // TODO: This query need its own separate rate limiter (as owned objects can theoretically be infinite), need a better way to handle this
192
286
  return this.queryClient.fetchQuery({
287
+ retry: this.retryFn,
288
+ retryDelay: 1000,
193
289
  queryKey: queryKeys.rpc.getOwnedObjects(input),
194
290
  queryFn: async () => {
195
- return await callWithRateLimit(this.tokenBucket, () =>
196
- this.client.getOwnedObjects(input)
291
+ const results = await callWithRateLimit(
292
+ this.tokenBucket,
293
+ async () => await this.client.getOwnedObjects(input)
197
294
  );
295
+ if (results && results.data.length > 0) {
296
+ results.data
297
+ .filter(
298
+ (
299
+ result
300
+ ): result is typeof result &
301
+ NonNullable<{ data: SuiObjectData }> => !!result.data
302
+ )
303
+ .forEach((result) => {
304
+ this.queryClient.setQueriesData(
305
+ {
306
+ exact: false,
307
+ queryKey: queryKeys.rpc.getObject(
308
+ result.data.objectId,
309
+ input.options ?? {}
310
+ ),
311
+ },
312
+ {
313
+ data: result.data,
314
+ error: null,
315
+ },
316
+ {
317
+ updatedAt: Date.now(),
318
+ }
319
+ );
320
+ });
321
+ }
322
+ return results;
198
323
  },
199
324
  });
200
325
  }
@@ -203,10 +328,13 @@ export class ScallopCache {
203
328
  input: GetDynamicFieldsParams
204
329
  ): Promise<DynamicFieldPage | null> {
205
330
  return this.queryClient.fetchQuery({
331
+ retry: this.retryFn,
332
+ retryDelay: 1000,
206
333
  queryKey: queryKeys.rpc.getDynamicFields(input),
207
334
  queryFn: async () => {
208
- return await callWithRateLimit(this.tokenBucket, () =>
209
- this.client.getDynamicFields(input)
335
+ return await callWithRateLimit(
336
+ this.tokenBucket,
337
+ async () => await this.client.getDynamicFields(input)
210
338
  );
211
339
  },
212
340
  });
@@ -216,11 +344,32 @@ export class ScallopCache {
216
344
  input: GetDynamicFieldObjectParams
217
345
  ): Promise<SuiObjectResponse | null> {
218
346
  return this.queryClient.fetchQuery({
347
+ retry: this.retryFn,
348
+ retryDelay: (attemptIndex) => Math.min(1000 * attemptIndex, 8000),
219
349
  queryKey: queryKeys.rpc.getDynamicFieldObject(input),
220
350
  queryFn: async () => {
221
- return await callWithRateLimit(this.tokenBucket, () =>
351
+ const result = await callWithRateLimit(this.tokenBucket, () =>
222
352
  this.client.getDynamicFieldObject(input)
223
353
  );
354
+ if (result?.data) {
355
+ this.queryClient.setQueriesData(
356
+ {
357
+ exact: false,
358
+ queryKey: queryKeys.rpc.getObject(result?.data.objectId, {
359
+ showContent: true,
360
+ showOwner: true,
361
+ }),
362
+ },
363
+ {
364
+ data: result.data,
365
+ error: null,
366
+ },
367
+ {
368
+ updatedAt: Date.now(),
369
+ }
370
+ );
371
+ }
372
+ return result;
224
373
  },
225
374
  });
226
375
  }
@@ -229,10 +378,13 @@ export class ScallopCache {
229
378
  owner: string
230
379
  ): Promise<{ [k: string]: string }> {
231
380
  return this.queryClient.fetchQuery({
381
+ retry: this.retryFn,
382
+ retryDelay: 1000,
232
383
  queryKey: queryKeys.rpc.getAllCoinBalances(owner),
233
384
  queryFn: async () => {
234
- const allBalances = await callWithRateLimit(this.tokenBucket, () =>
235
- this.client.getAllBalances({ owner })
385
+ const allBalances = await callWithRateLimit(
386
+ this.tokenBucket,
387
+ async () => await this.client.getAllBalances({ owner })
236
388
  );
237
389
  if (!allBalances) return {};
238
390
  const balances = allBalances.reduce(
@@ -232,7 +232,7 @@ export class ScallopClient {
232
232
  sign: S = true as S
233
233
  ): Promise<ScallopClientFnReturnType<S>> {
234
234
  const txBlock = this.builder.createTxBlock();
235
- txBlock.openObligationEntry();
235
+ await txBlock.openObligationEntry();
236
236
  if (sign) {
237
237
  return (await this.suiKit.signAndSendTxn(
238
238
  txBlock
@@ -283,9 +283,10 @@ export class ScallopClient {
283
283
  specificObligationId
284
284
  );
285
285
  } else {
286
- const [obligation, obligationKey, hotPotato] = txBlock.openObligation();
286
+ const [obligation, obligationKey, hotPotato] =
287
+ await txBlock.openObligation();
287
288
  await txBlock.addCollateralQuick(amount, collateralCoinName, obligation);
288
- txBlock.returnObligation(obligation, hotPotato);
289
+ await txBlock.returnObligation(obligation, hotPotato);
289
290
  txBlock.transferObjects([obligationKey], sender);
290
291
  }
291
292
 
@@ -425,7 +426,7 @@ export class ScallopClient {
425
426
  targetStakeAccount
426
427
  );
427
428
  } else {
428
- const account = txBlock.createStakeAccount(stakeMarketCoinName);
429
+ const account = await txBlock.createStakeAccount(stakeMarketCoinName);
429
430
  await txBlock.stakeQuick(marketCoin, stakeMarketCoinName, account);
430
431
  txBlock.transferObjects([account], sender);
431
432
  }
@@ -611,8 +612,12 @@ export class ScallopClient {
611
612
  const txBlock = this.builder.createTxBlock();
612
613
  const sender = walletAddress ?? this.walletAddress;
613
614
  txBlock.setSender(sender);
614
- const [coin, loan] = txBlock.borrowFlashLoan(amount, poolCoinName);
615
- txBlock.repayFlashLoan(await callback(txBlock, coin), loan, poolCoinName);
615
+ const [coin, loan] = await txBlock.borrowFlashLoan(amount, poolCoinName);
616
+ await txBlock.repayFlashLoan(
617
+ await callback(txBlock, coin),
618
+ loan,
619
+ poolCoinName
620
+ );
616
621
 
617
622
  if (sign) {
618
623
  return (await this.suiKit.signAndSendTxn(
@@ -649,7 +654,7 @@ export class ScallopClient {
649
654
  const sender = walletAddress ?? this.walletAddress;
650
655
  txBlock.setSender(sender);
651
656
 
652
- const stakeAccount = txBlock.createStakeAccount(marketCoinName);
657
+ const stakeAccount = await txBlock.createStakeAccount(marketCoinName);
653
658
  txBlock.transferObjects([stakeAccount], sender);
654
659
 
655
660
  if (sign) {
@@ -699,7 +704,7 @@ export class ScallopClient {
699
704
  if (targetStakeAccount) {
700
705
  await txBlock.stakeQuick(amount, stakeMarketCoinName, targetStakeAccount);
701
706
  } else {
702
- const account = txBlock.createStakeAccount(stakeMarketCoinName);
707
+ const account = await txBlock.createStakeAccount(stakeMarketCoinName);
703
708
  await txBlock.stakeQuick(amount, stakeMarketCoinName, account);
704
709
  txBlock.transferObjects([account], sender);
705
710
  }
@@ -814,7 +819,7 @@ export class ScallopClient {
814
819
  this.utils.parseCoinName<SupportStakeCoins>(stakeMarketCoinName);
815
820
 
816
821
  if (stakeMarketCoin) {
817
- const coin = txBlock.withdraw(stakeMarketCoin, stakeCoinName);
822
+ const coin = await txBlock.withdraw(stakeMarketCoin, stakeCoinName);
818
823
  await this.utils.mergeSimilarCoins(
819
824
  txBlock,
820
825
  coin,
@@ -965,6 +970,7 @@ export class ScallopClient {
965
970
  const rewardCoinsCollection: Record<string, TransactionResult[]> = {};
966
971
  const obligationAccount =
967
972
  await this.query.getObligationAccount(obligationId);
973
+ if (!obligationAccount) throw new Error('Obligation not found');
968
974
  const rewardCoinNames = Object.values(obligationAccount.borrowIncentives)
969
975
  .flatMap(({ rewards }) =>
970
976
  rewards.filter(({ availableClaimAmount }) => availableClaimAmount > 0)
@@ -1047,7 +1053,7 @@ export class ScallopClient {
1047
1053
  // if market coin found, mint sCoin
1048
1054
  if (toDestroyMarketCoin) {
1049
1055
  // mint new sCoin
1050
- const sCoin = txBlock.mintSCoin(
1056
+ const sCoin = await txBlock.mintSCoin(
1051
1057
  sCoinName as SupportSCoin,
1052
1058
  toDestroyMarketCoin
1053
1059
  );
@@ -14,11 +14,9 @@ import {
14
14
  getStakeRewardPool,
15
15
  getPythPrice,
16
16
  getMarketPools,
17
- getMarketPool,
18
17
  getMarketCollaterals,
19
18
  getMarketCollateral,
20
19
  getSpools,
21
- getSpool,
22
20
  queryBorrowIncentiveAccounts,
23
21
  getCoinAmounts,
24
22
  getCoinAmount,
@@ -27,7 +25,6 @@ import {
27
25
  getLendings,
28
26
  getLending,
29
27
  getObligationAccounts,
30
- getObligationAccount,
31
28
  getTotalValueLocked,
32
29
  queryVeScaKeyIdFromReferralBindings,
33
30
  getBindedObligationId,
@@ -41,13 +38,15 @@ import {
41
38
  getBorrowIncentivePools,
42
39
  getBorrowLimit,
43
40
  getIsolatedAssets,
44
- isIsolatedAsset,
41
+ // isIsolatedAsset,
45
42
  getSupplyLimit,
46
43
  getSCoinAmount,
47
44
  getSCoinAmounts,
48
45
  getSCoinSwapRate,
49
46
  getSCoinTotalSupply,
50
47
  getAllCoinPrices,
48
+ getAllAddresses,
49
+ isIsolatedAsset,
51
50
  } from '../queries';
52
51
  import {
53
52
  ScallopQueryParams,
@@ -188,6 +187,7 @@ export class ScallopQuery {
188
187
  /* ==================== Core Query Methods ==================== */
189
188
 
190
189
  /**
190
+ * @deprecated use getMarketPools
191
191
  * Query market data.
192
192
  * @param indexer - Whether to use indexer.
193
193
  * @return Market data.
@@ -211,7 +211,7 @@ export class ScallopQuery {
211
211
  * @return Market pools data.
212
212
  */
213
213
  public async getMarketPools(
214
- poolCoinNames?: SupportPoolCoins[],
214
+ poolCoinNames: SupportPoolCoins[] = [...SUPPORT_POOLS],
215
215
  args?: {
216
216
  coinPrices?: CoinPrices;
217
217
  indexer?: boolean;
@@ -235,18 +235,19 @@ export class ScallopQuery {
235
235
  public async getMarketPool(
236
236
  poolCoinName: SupportPoolCoins,
237
237
  args?: {
238
- marketObject?: SuiObjectData | null;
239
238
  coinPrice?: number;
240
239
  indexer?: boolean;
241
240
  }
242
241
  ) {
243
- return await getMarketPool(
244
- this,
245
- poolCoinName,
246
- args?.indexer,
247
- args?.marketObject,
248
- args?.coinPrice
249
- );
242
+ const marketPools = await this.getMarketPools(undefined, args);
243
+ return marketPools.pools[poolCoinName];
244
+ // return await getMarketPool(
245
+ // this,
246
+ // poolCoinName,
247
+ // args?.indexer,
248
+ // args?.marketObject,
249
+ // args?.coinPrice
250
+ // );
250
251
  }
251
252
 
252
253
  /**
@@ -418,13 +419,8 @@ export class ScallopQuery {
418
419
  indexer?: boolean;
419
420
  }
420
421
  ) {
421
- return await getSpool(
422
- this,
423
- stakeMarketCoinName,
424
- args?.indexer,
425
- args?.marketPool,
426
- args?.coinPrices
427
- );
422
+ const spools = await this.getSpools(undefined, args);
423
+ return spools[stakeMarketCoinName];
428
424
  }
429
425
 
430
426
  /**
@@ -546,7 +542,7 @@ export class ScallopQuery {
546
542
  public async getBorrowIncentivePools(
547
543
  coinNames?: SupportBorrowIncentiveCoins[],
548
544
  args?: {
549
- coinPrices: CoinPrices;
545
+ coinPrices?: CoinPrices;
550
546
  indexer?: boolean;
551
547
  marketPools?: MarketPools;
552
548
  }
@@ -618,7 +614,7 @@ export class ScallopQuery {
618
614
  */
619
615
  public async getObligationAccounts(
620
616
  ownerAddress: string = this.walletAddress,
621
- args?: { indexer: boolean }
617
+ args?: { indexer?: boolean }
622
618
  ) {
623
619
  return await getObligationAccounts(this, ownerAddress, args?.indexer);
624
620
  }
@@ -639,12 +635,16 @@ export class ScallopQuery {
639
635
  ownerAddress: string = this.walletAddress,
640
636
  args?: { indexer?: boolean }
641
637
  ) {
642
- return await getObligationAccount(
643
- this,
644
- obligationId,
645
- ownerAddress,
646
- args?.indexer
638
+ const results = await this.getObligationAccounts(ownerAddress, args);
639
+ return Object.values(results).find(
640
+ (obligation) => obligation?.obligationId === obligationId
647
641
  );
642
+ // return await getObligationAccount(
643
+ // this,
644
+ // obligationId,
645
+ // ownerAddress,
646
+ // args?.indexer
647
+ // );
648
648
  }
649
649
 
650
650
  /**
@@ -812,7 +812,7 @@ export class ScallopQuery {
812
812
  * Get list of isolated assets
813
813
  */
814
814
  public async getIsolatedAssets() {
815
- return await getIsolatedAssets(this.address);
815
+ return await getIsolatedAssets(this);
816
816
  }
817
817
 
818
818
  /**
@@ -841,4 +841,12 @@ export class ScallopQuery {
841
841
  }) {
842
842
  return getAllCoinPrices(this, args?.marketPools, args?.coinPrices);
843
843
  }
844
+
845
+ /**
846
+ * Query all address (lending pool, collateral pool, borrow dynamics, interest models) of all pool
847
+ * @returns
848
+ */
849
+ public async getPoolAddresses() {
850
+ return getAllAddresses(this);
851
+ }
844
852
  }
@@ -232,13 +232,14 @@ export class ScallopUtils {
232
232
  }
233
233
 
234
234
  /**
235
- * Convert sCoin name to coin name.
235
+ * Convert sCoin name to market coin name.
236
236
  * This function will parse new sCoin name `scallop_...` to its old market coin name which is shorter
237
237
  * e.g: `scallop_sui -> ssui
238
+ * if no `scallop_...` is encountered, return coinName
238
239
  * @return sCoin name
239
240
  */
240
- public parseCoinNameFromSCoinName(coinName: string) {
241
- return sCoinRawNameToName[coinName];
241
+ public parseSCoinTypeNameToMarketCoinName(coinName: string) {
242
+ return sCoinRawNameToName[coinName] ?? coinName;
242
243
  }
243
244
 
244
245
  /**
@@ -311,8 +312,14 @@ export class ScallopUtils {
311
312
  public parseCoinNameFromType<T extends SupportCoins>(
312
313
  coinType: string
313
314
  ): T extends SupportCoins ? T : SupportCoins;
315
+ public parseCoinNameFromType<T extends SupportSCoin>(
316
+ coinType: string
317
+ ): T extends SupportSCoin ? T : SupportSCoin;
314
318
  public parseCoinNameFromType(coinType: string) {
315
319
  coinType = normalizeStructTag(coinType);
320
+ if (sCoinTypeToName[coinType]) {
321
+ return sCoinTypeToName[coinType] as SupportSCoin;
322
+ }
316
323
 
317
324
  const coinTypeRegex = new RegExp(`((0x[^:]+::[^:]+::[^<>]+))(?![^<>]*<)`);
318
325
  const coinTypeMatch = coinType.match(coinTypeRegex);
@@ -553,7 +560,7 @@ export class ScallopUtils {
553
560
  const priceIds = priceIdPairs.map(([_, priceId]) => priceId);
554
561
 
555
562
  const pythConnection = new SuiPriceServiceConnection(endpoint, {
556
- timeout: 2000,
563
+ timeout: 4000,
557
564
  });
558
565
 
559
566
  try {
@@ -1,6 +1,5 @@
1
1
  import { normalizeStructTag } from '@mysten/sui/utils';
2
2
  import {
3
- sCoinRawNameToName,
4
3
  SUPPORT_BORROW_INCENTIVE_POOLS,
5
4
  SUPPORT_BORROW_INCENTIVE_REWARDS,
6
5
  } from '../constants';
@@ -66,7 +65,7 @@ export const getBorrowIncentivePools = async (
66
65
  const borrowIncentivePools: BorrowIncentivePools = {};
67
66
  marketPools =
68
67
  marketPools ??
69
- (await query.getMarketPools(undefined, { indexer, coinPrices }));
68
+ (await query.getMarketPools(undefined, { coinPrices, indexer })).pools;
70
69
  coinPrices = coinPrices ?? (await query.getAllCoinPrices({ marketPools }));
71
70
 
72
71
  if (indexer) {
@@ -100,8 +99,10 @@ export const getBorrowIncentivePools = async (
100
99
  const borrowIncentivePoolPoints: OptionalKeys<
101
100
  Record<SupportBorrowIncentiveRewardCoins, BorrowIncentivePoolPoints>
102
101
  > = {};
103
- const parsedBorrowIncentivePoolData =
104
- parseOriginBorrowIncentivePoolData(pool);
102
+ const parsedBorrowIncentivePoolData = parseOriginBorrowIncentivePoolData(
103
+ query.utils,
104
+ pool
105
+ );
105
106
 
106
107
  const poolCoinType = normalizeStructTag(pool.pool_type.name);
107
108
  const poolCoinName =
@@ -121,13 +122,10 @@ export const getBorrowIncentivePools = async (
121
122
  parsedBorrowIncentivePoolData.poolPoints
122
123
  )) {
123
124
  const rewardCoinType = poolPoint.pointType;
124
- let rewardCoinName = query.utils.parseCoinNameFromType(
125
+ const rewardCoinName = query.utils.parseCoinNameFromType(
125
126
  rewardCoinType
126
127
  ) as SupportBorrowIncentiveRewardCoins;
127
128
  // handle for scoin name
128
- if (sCoinRawNameToName[rewardCoinName]) {
129
- rewardCoinName = sCoinRawNameToName[rewardCoinName];
130
- }
131
129
  const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
132
130
  const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
133
131
 
@@ -17,9 +17,9 @@ const borrowLimitZod = zod.object({
17
17
  }),
18
18
  });
19
19
 
20
- // TODO: enable for production
21
- // const borrowLimitKeyType = `0xe7dbb371a9595631f7964b7ece42255ad0e738cc85fe6da26c7221b220f01af6::market_dynamic_keys::BorrowLimitKey`; // prod
22
- const borrowLimitKeyType = `0xb784ea287d944e478a3ceaa071f8885072cce6b7224cf245914dc2f9963f460e::market_dynamic_keys::BorrowLimitKey`;
20
+ const borrowLimitKeyType = `0xe7dbb371a9595631f7964b7ece42255ad0e738cc85fe6da26c7221b220f01af6::market_dynamic_keys::BorrowLimitKey`; // prod
21
+ // const borrowLimitKeyType = `0xb784ea287d944e478a3ceaa071f8885072cce6b7224cf245914dc2f9963f460e::market_dynamic_keys::BorrowLimitKey`;
22
+
23
23
  /**
24
24
  * Return supply limit of a pool (including the decimals)
25
25
  * @param utils