@scallop-io/sui-scallop-sdk 0.44.26 → 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
  }
@@ -4927,43 +5011,15 @@ var requireObligationInfo2 = async (...params) => {
4927
5011
  if (obligations.length === 0) {
4928
5012
  throw new Error(`No obligation found for sender ${sender}`);
4929
5013
  }
5014
+ const selectedObligation = obligations.find(
5015
+ (obligation) => obligation.id === obligationId || obligation.keyId === obligationKey
5016
+ ) ?? obligations[0];
4930
5017
  return {
4931
- obligationId: obligations[0].id,
4932
- obligationKey: obligations[0].keyId,
4933
- obligationLocked: obligations[0].locked
5018
+ obligationId: selectedObligation.id,
5019
+ obligationKey: selectedObligation.keyId,
5020
+ obligationLocked: selectedObligation.locked
4934
5021
  };
4935
5022
  };
4936
- var getBindedObligationId = async (builder, veScaKey) => {
4937
- const borrowIncentiveObjectId = builder.address.get("borrowIncentive.object");
4938
- const incentivePoolsId = builder.address.get(
4939
- "borrowIncentive.incentivePools"
4940
- );
4941
- const veScaPkgId = IS_VE_SCA_TEST ? "0xb220d034bdf335d77ae5bfbf6daf059c2cc7a1f719b12bfed75d1736fac038c8" : builder.address.get("vesca.id");
4942
- const client = builder.suiKit.client();
4943
- const incentivePoolsResponse = await client.getObject({
4944
- id: incentivePoolsId,
4945
- options: {
4946
- showContent: true
4947
- }
4948
- });
4949
- if (incentivePoolsResponse.data?.content?.dataType !== "moveObject")
4950
- return false;
4951
- const incentivePoolFields = incentivePoolsResponse.data.content.fields;
4952
- const veScaBindTableId = incentivePoolFields.ve_sca_bind.fields.id.id;
4953
- const keyType = `${borrowIncentiveObjectId}::typed_id::TypedID<${veScaPkgId}::ve_sca::VeScaKey>`;
4954
- const veScaBindTableResponse = await client.getDynamicFieldObject({
4955
- parentId: veScaBindTableId,
4956
- name: {
4957
- type: keyType,
4958
- value: veScaKey
4959
- }
4960
- });
4961
- if (veScaBindTableResponse.data?.content?.dataType !== "moveObject")
4962
- return false;
4963
- const veScaBindTableFields = veScaBindTableResponse.data.content.fields;
4964
- const obligationId = veScaBindTableFields.value.fields.id;
4965
- return obligationId;
4966
- };
4967
5023
  var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
4968
5024
  const borrowIncentiveIds = {
4969
5025
  borrowIncentivePkg: IS_VE_SCA_TEST ? "0x4d5a7cefa4147b4ace0ca845b20437d6ac0d32e5f2f855171f745472c2576246" : builder.address.get("borrowIncentive.id"),
@@ -5103,7 +5159,7 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
5103
5159
  const veSca = await requireVeSca(builder, txBlock, veScaKey);
5104
5160
  if (veSca) {
5105
5161
  const bindedObligationId = await getBindedObligationId(
5106
- builder,
5162
+ builder.query,
5107
5163
  veSca.keyId
5108
5164
  );
5109
5165
  if (!bindedObligationId || bindedObligationId === obligationArg) {