@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.
package/dist/index.mjs CHANGED
@@ -2442,6 +2442,63 @@ var queryBorrowIncentiveAccounts = async (query, obligationId, borrowIncentiveCo
2442
2442
  }, {});
2443
2443
  return borrowIncentiveAccounts;
2444
2444
  };
2445
+ var getBindedObligationId = async (query, veScaKeyId) => {
2446
+ const borrowIncentiveObjectId = query.address.get("borrowIncentive.object");
2447
+ const incentivePoolsId = query.address.get("borrowIncentive.incentivePools");
2448
+ const veScaPkgId = IS_VE_SCA_TEST ? "0xb220d034bdf335d77ae5bfbf6daf059c2cc7a1f719b12bfed75d1736fac038c8" : query.address.get("vesca.id");
2449
+ const client = query.suiKit.client();
2450
+ const incentivePoolsResponse = await client.getObject({
2451
+ id: incentivePoolsId,
2452
+ options: {
2453
+ showContent: true
2454
+ }
2455
+ });
2456
+ if (incentivePoolsResponse.data?.content?.dataType !== "moveObject")
2457
+ return null;
2458
+ const incentivePoolFields = incentivePoolsResponse.data.content.fields;
2459
+ const veScaBindTableId = incentivePoolFields.ve_sca_bind.fields.id.id;
2460
+ const keyType = `${borrowIncentiveObjectId}::typed_id::TypedID<${veScaPkgId}::ve_sca::VeScaKey>`;
2461
+ const veScaBindTableResponse = await client.getDynamicFieldObject({
2462
+ parentId: veScaBindTableId,
2463
+ name: {
2464
+ type: keyType,
2465
+ value: veScaKeyId
2466
+ }
2467
+ });
2468
+ if (veScaBindTableResponse.data?.content?.dataType !== "moveObject")
2469
+ return null;
2470
+ const veScaBindTableFields = veScaBindTableResponse.data.content.fields;
2471
+ const obligationId = veScaBindTableFields.value.fields.id;
2472
+ return obligationId;
2473
+ };
2474
+ var getBindedVeScaKey = async (query, obliationId) => {
2475
+ const borrowIncentiveObjectId = query.address.get("borrowIncentive.object");
2476
+ const incentiveAccountsId = query.address.get(
2477
+ "borrowIncentive.incentiveAccounts"
2478
+ );
2479
+ const corePkg = query.address.get("core.object");
2480
+ const client = query.suiKit.client();
2481
+ const incentiveAccountsObject = await client.getObject({
2482
+ id: incentiveAccountsId,
2483
+ options: {
2484
+ showContent: true
2485
+ }
2486
+ });
2487
+ if (incentiveAccountsObject.data?.content?.dataType !== "moveObject")
2488
+ return null;
2489
+ const incentiveAccountsTableId = incentiveAccountsObject.data.content.fields.accounts.fields.id.id;
2490
+ const bindedIncentiveAcc = await client.getDynamicFieldObject({
2491
+ parentId: incentiveAccountsTableId,
2492
+ name: {
2493
+ type: `${borrowIncentiveObjectId}::typed_id::TypedID<${corePkg}::obligation::Obligation>`,
2494
+ value: obliationId
2495
+ }
2496
+ });
2497
+ if (bindedIncentiveAcc.data?.content?.dataType !== "moveObject")
2498
+ return null;
2499
+ const bindedIncentiveAccFields = bindedIncentiveAcc.data.content.fields;
2500
+ return bindedIncentiveAccFields.value.fields.binded_ve_sca_key?.fields.id ?? null;
2501
+ };
2445
2502
 
2446
2503
  // src/queries/priceQuery.ts
2447
2504
  var getPythPrice = async (query, assetCoinName) => {
@@ -3027,11 +3084,19 @@ var getVeSca = async (query, veScaKeyId, ownerAddress) => {
3027
3084
  const veScaDynamicFieldObject = veScaDynamicFieldObjectResponse.data;
3028
3085
  if (veScaDynamicFieldObject && veScaDynamicFieldObject.content && veScaDynamicFieldObject.content.dataType === "moveObject" && "fields" in veScaDynamicFieldObject.content) {
3029
3086
  const dynamicFields = veScaDynamicFieldObject.content.fields.value.fields;
3087
+ const remainingLockPeriodInMilliseconds = Math.max(
3088
+ +dynamicFields.unlock_at * 1e3 - Date.now(),
3089
+ 0
3090
+ );
3091
+ const lockedScaAmount = String(dynamicFields.locked_sca_amount);
3092
+ const lockedScaCoin = BigNumber4(dynamicFields.locked_sca_amount).shiftedBy(-9).toNumber();
3093
+ const currentVeScaBalance = lockedScaCoin * (Math.floor(remainingLockPeriodInMilliseconds / 1e3) / MAX_LOCK_DURATION);
3030
3094
  vesca = {
3031
3095
  id: veScaDynamicFieldObject.objectId,
3032
3096
  keyId: veScaKeyId,
3033
- lockedScaAmount: BigNumber4(dynamicFields.locked_sca_amount).toNumber(),
3034
- lockedScaCoin: BigNumber4(dynamicFields.locked_sca_amount).shiftedBy(-9).toNumber(),
3097
+ lockedScaAmount,
3098
+ lockedScaCoin,
3099
+ currentVeScaBalance,
3035
3100
  unlockAt: BigNumber4(dynamicFields.unlock_at).toNumber()
3036
3101
  };
3037
3102
  }
@@ -3567,6 +3632,22 @@ var ScallopQuery = class {
3567
3632
  async getTvl(indexer = false) {
3568
3633
  return await getTotalValueLocked(this, indexer);
3569
3634
  }
3635
+ /**
3636
+ * Get binded obligationId from a veScaKey if it exists.
3637
+ * @param veScaKey
3638
+ * @returns obligationId
3639
+ */
3640
+ async getBindedObligationId(veScaKey) {
3641
+ return await getBindedObligationId(this, veScaKey);
3642
+ }
3643
+ /**
3644
+ * Get binded veSCA key from a obligationId if it exists.
3645
+ * @param obligationId
3646
+ * @returns veScaKey
3647
+ */
3648
+ async getBindedVeScaKey(obligationId) {
3649
+ return await getBindedVeScaKey(this, obligationId);
3650
+ }
3570
3651
  };
3571
3652
 
3572
3653
  // src/constants/pyth.ts
@@ -4596,7 +4677,10 @@ var requireVeSca = async (...params) => {
4596
4677
  if (veScas.length === 0) {
4597
4678
  return void 0;
4598
4679
  }
4599
- return veScas[0];
4680
+ return veScas.reduce(
4681
+ (prev, acc) => acc.currentVeScaBalance > prev.currentVeScaBalance ? acc : prev,
4682
+ veScas[0]
4683
+ );
4600
4684
  };
4601
4685
  var generateNormalVeScaMethod = ({
4602
4686
  builder,
@@ -4730,7 +4814,7 @@ var generateQuickVeScaMethod = ({
4730
4814
  const veScaKey = txBlock.lockSca(scaCoin, newUnlockAt);
4731
4815
  transferObjects.push(veScaKey);
4732
4816
  } else {
4733
- if (veSca.lockedScaAmount !== 0) {
4817
+ if (veSca.lockedScaCoin !== 0) {
4734
4818
  const unlockedSca = txBlock.redeemSca(veSca.keyId);
4735
4819
  transferObjects.push(unlockedSca);
4736
4820
  }
@@ -4790,7 +4874,7 @@ var generateQuickVeScaMethod = ({
4790
4874
  checkRenewExpiredVeSca(scaAmount, lockPeriodInDays, veSca?.unlockAt);
4791
4875
  if (veSca) {
4792
4876
  const transferObjects = [];
4793
- if (veSca.lockedScaAmount !== 0) {
4877
+ if (veSca.lockedScaCoin !== 0) {
4794
4878
  const unlockedSca = txBlock.redeemSca(veSca.keyId);
4795
4879
  transferObjects.push(unlockedSca);
4796
4880
  }
@@ -4862,43 +4946,15 @@ var requireObligationInfo2 = async (...params) => {
4862
4946
  if (obligations.length === 0) {
4863
4947
  throw new Error(`No obligation found for sender ${sender}`);
4864
4948
  }
4949
+ const selectedObligation = obligations.find(
4950
+ (obligation) => obligation.id === obligationId || obligation.keyId === obligationKey
4951
+ ) ?? obligations[0];
4865
4952
  return {
4866
- obligationId: obligations[0].id,
4867
- obligationKey: obligations[0].keyId,
4868
- obligationLocked: obligations[0].locked
4953
+ obligationId: selectedObligation.id,
4954
+ obligationKey: selectedObligation.keyId,
4955
+ obligationLocked: selectedObligation.locked
4869
4956
  };
4870
4957
  };
4871
- var getBindedObligationId = async (builder, veScaKey) => {
4872
- const borrowIncentiveObjectId = builder.address.get("borrowIncentive.object");
4873
- const incentivePoolsId = builder.address.get(
4874
- "borrowIncentive.incentivePools"
4875
- );
4876
- const veScaPkgId = IS_VE_SCA_TEST ? "0xb220d034bdf335d77ae5bfbf6daf059c2cc7a1f719b12bfed75d1736fac038c8" : builder.address.get("vesca.id");
4877
- const client = builder.suiKit.client();
4878
- const incentivePoolsResponse = await client.getObject({
4879
- id: incentivePoolsId,
4880
- options: {
4881
- showContent: true
4882
- }
4883
- });
4884
- if (incentivePoolsResponse.data?.content?.dataType !== "moveObject")
4885
- return false;
4886
- const incentivePoolFields = incentivePoolsResponse.data.content.fields;
4887
- const veScaBindTableId = incentivePoolFields.ve_sca_bind.fields.id.id;
4888
- const keyType = `${borrowIncentiveObjectId}::typed_id::TypedID<${veScaPkgId}::ve_sca::VeScaKey>`;
4889
- const veScaBindTableResponse = await client.getDynamicFieldObject({
4890
- parentId: veScaBindTableId,
4891
- name: {
4892
- type: keyType,
4893
- value: veScaKey
4894
- }
4895
- });
4896
- if (veScaBindTableResponse.data?.content?.dataType !== "moveObject")
4897
- return false;
4898
- const veScaBindTableFields = veScaBindTableResponse.data.content.fields;
4899
- const obligationId = veScaBindTableFields.value.fields.id;
4900
- return obligationId;
4901
- };
4902
4958
  var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
4903
4959
  const borrowIncentiveIds = {
4904
4960
  borrowIncentivePkg: IS_VE_SCA_TEST ? "0x4d5a7cefa4147b4ace0ca845b20437d6ac0d32e5f2f855171f745472c2576246" : builder.address.get("borrowIncentive.id"),
@@ -5038,7 +5094,7 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
5038
5094
  const veSca = await requireVeSca(builder, txBlock, veScaKey);
5039
5095
  if (veSca) {
5040
5096
  const bindedObligationId = await getBindedObligationId(
5041
- builder,
5097
+ builder.query,
5042
5098
  veSca.keyId
5043
5099
  );
5044
5100
  if (!bindedObligationId || bindedObligationId === obligationArg) {