@scallop-io/sui-scallop-sdk 0.46.32 → 0.46.34

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scallop-io/sui-scallop-sdk",
3
- "version": "0.46.32",
3
+ "version": "0.46.34",
4
4
  "description": "Typescript sdk for interacting with Scallop contract on SUI",
5
5
  "keywords": [
6
6
  "sui",
@@ -18,8 +18,8 @@ export const PROTOCOL_OBJECT_ID = IS_VE_SCA_TEST
18
18
  // '0x87ddec2984645dbbe2403a509cc6edf393a43acdba9b77d45da2bcbefcf733c1' as const;
19
19
 
20
20
  export const BORROW_FEE_PROTOCOL_ID = IS_VE_SCA_TEST
21
- ? ('0xc9f859f98ca352a11b97a038c4b4162bee437b8df8caa047990fe9cb03d4f778' as const)
22
- : ('0xc38f849e81cfe46d4e4320f508ea7dda42934a329d5a6571bb4c3cb6ea63f5da' as const); // test environment
21
+ ? ('0xc9f859f98ca352a11b97a038c4b4162bee437b8df8caa047990fe9cb03d4f778' as const) // test environment
22
+ : ('0xc38f849e81cfe46d4e4320f508ea7dda42934a329d5a6571bb4c3cb6ea63f5da' as const);
23
23
  // export const BORROW_FEE_PROTOCOL_ID =
24
24
  // '0x87ddec2984645dbbe2403a509cc6edf393a43acdba9b77d45da2bcbefcf733c1' as const;
25
25
 
@@ -168,6 +168,9 @@ export class ScallopCache {
168
168
  JSON.stringify(objectIds),
169
169
  this.suiKit.currentAddress(),
170
170
  ];
171
+ if (options) {
172
+ queryKey.push(JSON.stringify(options));
173
+ }
171
174
  return this.queryClient.fetchQuery({
172
175
  queryKey,
173
176
  queryFn: async () => {
@@ -213,9 +216,6 @@ export class ScallopCache {
213
216
  if (input.cursor) {
214
217
  queryKey.push(JSON.stringify(input.cursor));
215
218
  }
216
- if (input.cursor) {
217
- queryKey.push(JSON.stringify(input.cursor));
218
- }
219
219
  if (input.limit) {
220
220
  queryKey.push(JSON.stringify(input.limit));
221
221
  }
@@ -234,6 +234,7 @@ export class ScallopCache {
234
234
  const queryKey = [
235
235
  'getDynamicFieldObject',
236
236
  input.parentId,
237
+ input.name.type,
237
238
  input.name.value,
238
239
  ];
239
240
  return this.queryClient.fetchQuery({
@@ -215,15 +215,13 @@ export const getBindedObligationId = async (
215
215
  const incentivePoolsId = query.address.get('borrowIncentive.incentivePools');
216
216
  const veScaObjId = query.address.get('vesca.object');
217
217
 
218
- const client = query.suiKit.client();
219
-
220
218
  // get incentive pools
221
- const incentivePoolsResponse = await client.getObject({
222
- id: incentivePoolsId,
223
- options: {
219
+ const incentivePoolsResponse = await query.cache.queryGetObject(
220
+ incentivePoolsId,
221
+ {
224
222
  showContent: true,
225
- },
226
- });
223
+ }
224
+ );
227
225
 
228
226
  if (incentivePoolsResponse.data?.content?.dataType !== 'moveObject')
229
227
  return null;
@@ -233,7 +231,7 @@ export const getBindedObligationId = async (
233
231
 
234
232
  // check if veSca is inside the bind table
235
233
  const keyType = `${borrowIncentiveObjectId}::typed_id::TypedID<${veScaObjId}::ve_sca::VeScaKey>`;
236
- const veScaBindTableResponse = await client.getDynamicFieldObject({
234
+ const veScaBindTableResponse = await query.cache.queryGetDynamicFieldObject({
237
235
  parentId: veScaBindTableId,
238
236
  name: {
239
237
  type: keyType,
@@ -260,15 +258,14 @@ export const getBindedVeScaKey = async (
260
258
  'borrowIncentive.incentiveAccounts'
261
259
  );
262
260
  const corePkg = query.address.get('core.object');
263
- const client = query.suiKit.client();
264
261
 
265
262
  // get IncentiveAccounts object
266
- const incentiveAccountsObject = await client.getObject({
267
- id: incentiveAccountsId,
268
- options: {
263
+ const incentiveAccountsObject = await query.cache.queryGetObject(
264
+ incentiveAccountsId,
265
+ {
269
266
  showContent: true,
270
- },
271
- });
267
+ }
268
+ );
272
269
  if (incentiveAccountsObject.data?.content?.dataType !== 'moveObject')
273
270
  return null;
274
271
  const incentiveAccountsTableId = (
@@ -276,7 +273,7 @@ export const getBindedVeScaKey = async (
276
273
  ).accounts.fields.id.id;
277
274
 
278
275
  // Search in the table
279
- const bindedIncentiveAcc = await client.getDynamicFieldObject({
276
+ const bindedIncentiveAcc = await query.cache.queryGetDynamicFieldObject({
280
277
  parentId: incentiveAccountsTableId,
281
278
  name: {
282
279
  type: `${borrowIncentiveObjectId}::typed_id::TypedID<${corePkg}::obligation::Obligation>`,
@@ -433,12 +433,12 @@ export const getObligationAccount = async (
433
433
  const increasedRate = debt?.borrowIndex
434
434
  ? marketPool.borrowIndex / Number(debt.borrowIndex) - 1
435
435
  : 0;
436
- const borrowedAmount = BigNumber(debt?.amount ?? 0);
437
- const borrowedCoin = borrowedAmount.shiftedBy(-1 * coinDecimal);
438
-
439
- const requiredRepayAmount = borrowedAmount.multipliedBy(
436
+ const borrowedAmount = BigNumber(debt?.amount ?? 0).multipliedBy(
440
437
  increasedRate + 1
441
438
  );
439
+ const borrowedCoin = borrowedAmount.shiftedBy(-1 * coinDecimal);
440
+
441
+ const requiredRepayAmount = borrowedAmount;
442
442
  const requiredRepayCoin = requiredRepayAmount.shiftedBy(-1 * coinDecimal);
443
443
 
444
444
  const availableRepayAmount = BigNumber(coinAmount);
@@ -486,7 +486,6 @@ export const getObligationAccount = async (
486
486
  )) {
487
487
  const coinName = poolCoinName as SupportBorrowIncentiveCoins;
488
488
  const borrowIncentivePool = borrowIncentivePools[coinName];
489
-
490
489
  if (borrowIncentivePool) {
491
490
  const rewards: ObligationBorrowIcentiveReward[] = [];
492
491
  for (const rewardCoinName of SUPPORT_BORROW_INCENTIVE_REWARDS) {
@@ -499,9 +498,12 @@ export const getObligationAccount = async (
499
498
  const accountBorrowedAmount = BigNumber(accountPoint.weightedAmount);
500
499
  const baseIndexRate = 1_000_000_000;
501
500
  const increasedPointRate = poolPoint.currentPointIndex
502
- ? BigNumber(
503
- poolPoint.currentPointIndex - accountPoint.index
504
- ).dividedBy(baseIndexRate)
501
+ ? Math.max(
502
+ BigNumber(poolPoint.currentPointIndex - accountPoint.index)
503
+ .dividedBy(baseIndexRate)
504
+ .toNumber(),
505
+ 0
506
+ )
505
507
  : 1;
506
508
  availableClaimAmount = availableClaimAmount.plus(
507
509
  accountBorrowedAmount
@@ -530,7 +532,7 @@ export const getObligationAccount = async (
530
532
  .toNumber()
531
533
  : 1;
532
534
 
533
- if (availableClaimAmount.isGreaterThan(0)) {
535
+ if (availableClaimAmount.isGreaterThanOrEqualTo(0)) {
534
536
  rewards.push({
535
537
  coinName: poolPoint.coinName,
536
538
  coinType: poolPoint.coinType,