@scallop-io/sui-scallop-sdk 0.44.27 → 0.44.28

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.
@@ -2,13 +2,6 @@ import { TransactionBlock } from '@mysten/sui.js/transactions';
2
2
  import { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
3
3
  import type { ScallopBuilder } from '../models';
4
4
  import type { BorrowIncentiveTxBlock, ScallopTxBlock } from '../types';
5
- /**
6
- * Check veSca bind status
7
- * @param query
8
- * @param veScaKey
9
- * @returns
10
- */
11
- export declare const getBindedObligationId: (builder: ScallopBuilder, veScaKey: string) => Promise<string | false>;
12
5
  /**
13
6
  * Create an enhanced transaction block instance for interaction with borrow incentive modules of the Scallop contract.
14
7
  *
package/dist/index.js CHANGED
@@ -2514,6 +2514,63 @@ var queryBorrowIncentiveAccounts = async (query, obligationId, borrowIncentiveCo
2514
2514
  }, {});
2515
2515
  return borrowIncentiveAccounts;
2516
2516
  };
2517
+ var getBindedObligationId = async (query, veScaKeyId) => {
2518
+ const borrowIncentiveObjectId = query.address.get("borrowIncentive.object");
2519
+ const incentivePoolsId = query.address.get("borrowIncentive.incentivePools");
2520
+ const veScaPkgId = IS_VE_SCA_TEST ? "0xb220d034bdf335d77ae5bfbf6daf059c2cc7a1f719b12bfed75d1736fac038c8" : query.address.get("vesca.id");
2521
+ const client = query.suiKit.client();
2522
+ const incentivePoolsResponse = await client.getObject({
2523
+ id: incentivePoolsId,
2524
+ options: {
2525
+ showContent: true
2526
+ }
2527
+ });
2528
+ if (incentivePoolsResponse.data?.content?.dataType !== "moveObject")
2529
+ return null;
2530
+ const incentivePoolFields = incentivePoolsResponse.data.content.fields;
2531
+ const veScaBindTableId = incentivePoolFields.ve_sca_bind.fields.id.id;
2532
+ const keyType = `${borrowIncentiveObjectId}::typed_id::TypedID<${veScaPkgId}::ve_sca::VeScaKey>`;
2533
+ const veScaBindTableResponse = await client.getDynamicFieldObject({
2534
+ parentId: veScaBindTableId,
2535
+ name: {
2536
+ type: keyType,
2537
+ value: veScaKeyId
2538
+ }
2539
+ });
2540
+ if (veScaBindTableResponse.data?.content?.dataType !== "moveObject")
2541
+ return null;
2542
+ const veScaBindTableFields = veScaBindTableResponse.data.content.fields;
2543
+ const obligationId = veScaBindTableFields.value.fields.id;
2544
+ return obligationId;
2545
+ };
2546
+ var getBindedVeScaKey = async (query, obliationId) => {
2547
+ const borrowIncentiveObjectId = query.address.get("borrowIncentive.object");
2548
+ const incentiveAccountsId = query.address.get(
2549
+ "borrowIncentive.incentiveAccounts"
2550
+ );
2551
+ const corePkg = query.address.get("core.object");
2552
+ const client = query.suiKit.client();
2553
+ const incentiveAccountsObject = await client.getObject({
2554
+ id: incentiveAccountsId,
2555
+ options: {
2556
+ showContent: true
2557
+ }
2558
+ });
2559
+ if (incentiveAccountsObject.data?.content?.dataType !== "moveObject")
2560
+ return null;
2561
+ const incentiveAccountsTableId = incentiveAccountsObject.data.content.fields.accounts.fields.id.id;
2562
+ const bindedIncentiveAcc = await client.getDynamicFieldObject({
2563
+ parentId: incentiveAccountsTableId,
2564
+ name: {
2565
+ type: `${borrowIncentiveObjectId}::typed_id::TypedID<${corePkg}::obligation::Obligation>`,
2566
+ value: obliationId
2567
+ }
2568
+ });
2569
+ if (bindedIncentiveAcc.data?.content?.dataType !== "moveObject")
2570
+ return null;
2571
+ const bindedIncentiveAccFields = bindedIncentiveAcc.data.content.fields;
2572
+ return bindedIncentiveAccFields.value.fields.binded_ve_sca_key?.fields.id ?? null;
2573
+ };
2517
2574
 
2518
2575
  // src/queries/priceQuery.ts
2519
2576
  var getPythPrice = async (query, assetCoinName) => {
@@ -3099,11 +3156,19 @@ var getVeSca = async (query, veScaKeyId, ownerAddress) => {
3099
3156
  const veScaDynamicFieldObject = veScaDynamicFieldObjectResponse.data;
3100
3157
  if (veScaDynamicFieldObject && veScaDynamicFieldObject.content && veScaDynamicFieldObject.content.dataType === "moveObject" && "fields" in veScaDynamicFieldObject.content) {
3101
3158
  const dynamicFields = veScaDynamicFieldObject.content.fields.value.fields;
3159
+ const remainingLockPeriodInMilliseconds = Math.max(
3160
+ +dynamicFields.unlock_at * 1e3 - Date.now(),
3161
+ 0
3162
+ );
3163
+ const lockedScaAmount = String(dynamicFields.locked_sca_amount);
3164
+ const lockedScaCoin = (0, import_bignumber4.default)(dynamicFields.locked_sca_amount).shiftedBy(-9).toNumber();
3165
+ const currentVeScaBalance = lockedScaCoin * (Math.floor(remainingLockPeriodInMilliseconds / 1e3) / MAX_LOCK_DURATION);
3102
3166
  vesca = {
3103
3167
  id: veScaDynamicFieldObject.objectId,
3104
3168
  keyId: veScaKeyId,
3105
- lockedScaAmount: (0, import_bignumber4.default)(dynamicFields.locked_sca_amount).toNumber(),
3106
- lockedScaCoin: (0, import_bignumber4.default)(dynamicFields.locked_sca_amount).shiftedBy(-9).toNumber(),
3169
+ lockedScaAmount,
3170
+ lockedScaCoin,
3171
+ currentVeScaBalance,
3107
3172
  unlockAt: (0, import_bignumber4.default)(dynamicFields.unlock_at).toNumber()
3108
3173
  };
3109
3174
  }
@@ -3639,6 +3704,22 @@ var ScallopQuery = class {
3639
3704
  async getTvl(indexer = false) {
3640
3705
  return await getTotalValueLocked(this, indexer);
3641
3706
  }
3707
+ /**
3708
+ * Get binded obligationId from a veScaKey if it exists.
3709
+ * @param veScaKey
3710
+ * @returns obligationId
3711
+ */
3712
+ async getBindedObligationId(veScaKey) {
3713
+ return await getBindedObligationId(this, veScaKey);
3714
+ }
3715
+ /**
3716
+ * Get binded veSCA key from a obligationId if it exists.
3717
+ * @param obligationId
3718
+ * @returns veScaKey
3719
+ */
3720
+ async getBindedVeScaKey(obligationId) {
3721
+ return await getBindedVeScaKey(this, obligationId);
3722
+ }
3642
3723
  };
3643
3724
 
3644
3725
  // src/constants/pyth.ts
@@ -4661,7 +4742,10 @@ var requireVeSca = async (...params) => {
4661
4742
  if (veScas.length === 0) {
4662
4743
  return void 0;
4663
4744
  }
4664
- return veScas[0];
4745
+ return veScas.reduce(
4746
+ (prev, acc) => acc.currentVeScaBalance > prev.currentVeScaBalance ? acc : prev,
4747
+ veScas[0]
4748
+ );
4665
4749
  };
4666
4750
  var generateNormalVeScaMethod = ({
4667
4751
  builder,
@@ -4795,7 +4879,7 @@ var generateQuickVeScaMethod = ({
4795
4879
  const veScaKey = txBlock.lockSca(scaCoin, newUnlockAt);
4796
4880
  transferObjects.push(veScaKey);
4797
4881
  } else {
4798
- if (veSca.lockedScaAmount !== 0) {
4882
+ if (veSca.lockedScaCoin !== 0) {
4799
4883
  const unlockedSca = txBlock.redeemSca(veSca.keyId);
4800
4884
  transferObjects.push(unlockedSca);
4801
4885
  }
@@ -4855,7 +4939,7 @@ var generateQuickVeScaMethod = ({
4855
4939
  checkRenewExpiredVeSca(scaAmount, lockPeriodInDays, veSca?.unlockAt);
4856
4940
  if (veSca) {
4857
4941
  const transferObjects = [];
4858
- if (veSca.lockedScaAmount !== 0) {
4942
+ if (veSca.lockedScaCoin !== 0) {
4859
4943
  const unlockedSca = txBlock.redeemSca(veSca.keyId);
4860
4944
  transferObjects.push(unlockedSca);
4861
4945
  }
@@ -4936,37 +5020,6 @@ var requireObligationInfo2 = async (...params) => {
4936
5020
  obligationLocked: selectedObligation.locked
4937
5021
  };
4938
5022
  };
4939
- var getBindedObligationId = async (builder, veScaKey) => {
4940
- const borrowIncentiveObjectId = builder.address.get("borrowIncentive.object");
4941
- const incentivePoolsId = builder.address.get(
4942
- "borrowIncentive.incentivePools"
4943
- );
4944
- const veScaPkgId = IS_VE_SCA_TEST ? "0xb220d034bdf335d77ae5bfbf6daf059c2cc7a1f719b12bfed75d1736fac038c8" : builder.address.get("vesca.id");
4945
- const client = builder.suiKit.client();
4946
- const incentivePoolsResponse = await client.getObject({
4947
- id: incentivePoolsId,
4948
- options: {
4949
- showContent: true
4950
- }
4951
- });
4952
- if (incentivePoolsResponse.data?.content?.dataType !== "moveObject")
4953
- return false;
4954
- const incentivePoolFields = incentivePoolsResponse.data.content.fields;
4955
- const veScaBindTableId = incentivePoolFields.ve_sca_bind.fields.id.id;
4956
- const keyType = `${borrowIncentiveObjectId}::typed_id::TypedID<${veScaPkgId}::ve_sca::VeScaKey>`;
4957
- const veScaBindTableResponse = await client.getDynamicFieldObject({
4958
- parentId: veScaBindTableId,
4959
- name: {
4960
- type: keyType,
4961
- value: veScaKey
4962
- }
4963
- });
4964
- if (veScaBindTableResponse.data?.content?.dataType !== "moveObject")
4965
- return false;
4966
- const veScaBindTableFields = veScaBindTableResponse.data.content.fields;
4967
- const obligationId = veScaBindTableFields.value.fields.id;
4968
- return obligationId;
4969
- };
4970
5023
  var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
4971
5024
  const borrowIncentiveIds = {
4972
5025
  borrowIncentivePkg: IS_VE_SCA_TEST ? "0x4d5a7cefa4147b4ace0ca845b20437d6ac0d32e5f2f855171f745472c2576246" : builder.address.get("borrowIncentive.id"),
@@ -5106,7 +5159,7 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
5106
5159
  const veSca = await requireVeSca(builder, txBlock, veScaKey);
5107
5160
  if (veSca) {
5108
5161
  const bindedObligationId = await getBindedObligationId(
5109
- builder,
5162
+ builder.query,
5110
5163
  veSca.keyId
5111
5164
  );
5112
5165
  if (!bindedObligationId || bindedObligationId === obligationArg) {