@scallop-io/sui-scallop-sdk 0.47.1 → 0.47.3

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.
@@ -7,5 +7,8 @@ import type { SupportAssetCoins } from '../types';
7
7
  * @param builder - The scallop builder.
8
8
  * @param txBlock - TxBlock created by SuiKit.
9
9
  * @param assetCoinNames - Specific an array of support asset coin name.
10
+ * @param options - The options for update oracles.
10
11
  */
11
- export declare const updateOracles: (builder: ScallopBuilder, txBlock: SuiKitTxBlock, assetCoinNames?: SupportAssetCoins[]) => Promise<void>;
12
+ export declare const updateOracles: (builder: ScallopBuilder, txBlock: SuiKitTxBlock, assetCoinNames?: SupportAssetCoins[], options?: {
13
+ usePythPullModel: boolean;
14
+ }) => Promise<void>;
package/dist/index.js CHANGED
@@ -3495,7 +3495,7 @@ var getBindedObligationId = async ({
3495
3495
  };
3496
3496
  var getBindedVeScaKey = async ({
3497
3497
  address
3498
- }, obliationId) => {
3498
+ }, obligationId) => {
3499
3499
  const borrowIncentiveObjectId = address.get("borrowIncentive.object");
3500
3500
  const incentiveAccountsId = address.get("borrowIncentive.incentiveAccounts");
3501
3501
  const corePkg = address.get("core.object");
@@ -3512,7 +3512,7 @@ var getBindedVeScaKey = async ({
3512
3512
  parentId: incentiveAccountsTableId,
3513
3513
  name: {
3514
3514
  type: `${borrowIncentiveObjectId}::typed_id::TypedID<${corePkg}::obligation::Obligation>`,
3515
- value: obliationId
3515
+ value: obligationId
3516
3516
  }
3517
3517
  });
3518
3518
  if (bindedIncentiveAcc?.data?.content?.dataType !== "moveObject")
@@ -4805,12 +4805,13 @@ var import_sui_kit5 = require("@scallop-io/sui-kit");
4805
4805
  // src/builders/oracle.ts
4806
4806
  var import_utils12 = require("@mysten/sui.js/utils");
4807
4807
  var import_pyth_sui_js2 = require("@pythnetwork/pyth-sui-js");
4808
- var updateOracles = async (builder, txBlock, assetCoinNames) => {
4808
+ var updateOracles = async (builder, txBlock, assetCoinNames, options = { usePythPullModel: true }) => {
4809
+ const usePythPullModel = builder.params.usePythPullModel ?? options.usePythPullModel;
4809
4810
  assetCoinNames = assetCoinNames ?? [
4810
4811
  .../* @__PURE__ */ new Set([...SUPPORT_POOLS, ...SUPPORT_COLLATERALS])
4811
4812
  ];
4812
4813
  const rules = builder.isTestnet ? ["pyth"] : ["pyth"];
4813
- if (rules.includes("pyth")) {
4814
+ if (usePythPullModel && rules.includes("pyth")) {
4814
4815
  const pythClient = new import_pyth_sui_js2.SuiPythClient(
4815
4816
  builder.suiKit.client(),
4816
4817
  builder.address.get("core.oracles.pyth.state"),
@@ -5559,11 +5560,236 @@ var newSpoolTxBlock = (builder, initTxBlock) => {
5559
5560
 
5560
5561
  // src/builders/borrowIncentiveBuilder.ts
5561
5562
  var import_transactions3 = require("@mysten/sui.js/transactions");
5562
- var import_utils18 = require("@mysten/sui.js/utils");
5563
- var import_sui_kit8 = require("@scallop-io/sui-kit");
5563
+ var import_utils17 = require("@mysten/sui.js/utils");
5564
+ var import_sui_kit7 = require("@scallop-io/sui-kit");
5565
+ var requireObligationInfo2 = async (...params) => {
5566
+ const [builder, txBlock, obligationId, obligationKey] = params;
5567
+ if (params.length === 4 && obligationId && obligationKey && typeof obligationId === "string") {
5568
+ const obligationLocked = await getObligationLocked(
5569
+ builder.cache,
5570
+ obligationId
5571
+ );
5572
+ return { obligationId, obligationKey, obligationLocked };
5573
+ }
5574
+ const sender = requireSender(txBlock);
5575
+ const obligations = await getObligations(builder, sender);
5576
+ if (obligations.length === 0) {
5577
+ throw new Error(`No obligation found for sender ${sender}`);
5578
+ }
5579
+ const selectedObligation = obligations.find(
5580
+ (obligation) => obligation.id === obligationId || obligation.keyId === obligationKey
5581
+ ) ?? obligations[0];
5582
+ return {
5583
+ obligationId: selectedObligation.id,
5584
+ obligationKey: selectedObligation.keyId,
5585
+ obligationLocked: selectedObligation.locked
5586
+ };
5587
+ };
5588
+ var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
5589
+ const borrowIncentiveIds = {
5590
+ borrowIncentivePkg: builder.address.get("borrowIncentive.id"),
5591
+ query: builder.address.get("borrowIncentive.query"),
5592
+ config: builder.address.get("borrowIncentive.config"),
5593
+ incentivePools: builder.address.get("borrowIncentive.incentivePools"),
5594
+ incentiveAccounts: builder.address.get(
5595
+ "borrowIncentive.incentiveAccounts"
5596
+ ),
5597
+ obligationAccessStore: builder.address.get("core.obligationAccessStore")
5598
+ };
5599
+ const veScaIds = {
5600
+ table: builder.address.get("vesca.table"),
5601
+ treasury: builder.address.get("vesca.treasury"),
5602
+ config: builder.address.get("vesca.config")
5603
+ };
5604
+ return {
5605
+ stakeObligation: (obligationId, obligationKey) => {
5606
+ txBlock.moveCall(
5607
+ `${borrowIncentiveIds.borrowIncentivePkg}::user::stake`,
5608
+ [
5609
+ borrowIncentiveIds.config,
5610
+ borrowIncentiveIds.incentivePools,
5611
+ borrowIncentiveIds.incentiveAccounts,
5612
+ obligationKey,
5613
+ obligationId,
5614
+ borrowIncentiveIds.obligationAccessStore,
5615
+ import_utils17.SUI_CLOCK_OBJECT_ID
5616
+ ]
5617
+ );
5618
+ },
5619
+ stakeObligationWithVesca: (obligationId, obligationKey, veScaKey) => {
5620
+ txBlock.moveCall(
5621
+ `${borrowIncentiveIds.borrowIncentivePkg}::user::stake_with_ve_sca`,
5622
+ [
5623
+ borrowIncentiveIds.config,
5624
+ borrowIncentiveIds.incentivePools,
5625
+ borrowIncentiveIds.incentiveAccounts,
5626
+ obligationKey,
5627
+ obligationId,
5628
+ borrowIncentiveIds.obligationAccessStore,
5629
+ veScaIds.config,
5630
+ veScaIds.treasury,
5631
+ veScaIds.table,
5632
+ veScaKey,
5633
+ import_utils17.SUI_CLOCK_OBJECT_ID
5634
+ ],
5635
+ []
5636
+ );
5637
+ },
5638
+ unstakeObligation: (obligationId, obligationKey) => {
5639
+ txBlock.moveCall(
5640
+ `${borrowIncentiveIds.borrowIncentivePkg}::user::unstake`,
5641
+ [
5642
+ borrowIncentiveIds.config,
5643
+ borrowIncentiveIds.incentivePools,
5644
+ borrowIncentiveIds.incentiveAccounts,
5645
+ obligationKey,
5646
+ obligationId,
5647
+ import_utils17.SUI_CLOCK_OBJECT_ID
5648
+ ]
5649
+ );
5650
+ },
5651
+ claimBorrowIncentive: (obligationId, obligationKey, coinName, rewardCoinName) => {
5652
+ const rewardCoinNames = builder.utils.getBorrowIncentiveRewardCoinName(coinName);
5653
+ if (rewardCoinNames.includes(rewardCoinName) === false) {
5654
+ throw new Error(`Invalid reward coin name ${rewardCoinName}`);
5655
+ }
5656
+ const rewardType = builder.utils.parseCoinType(rewardCoinName);
5657
+ return txBlock.moveCall(
5658
+ `${borrowIncentiveIds.borrowIncentivePkg}::user::redeem_rewards`,
5659
+ [
5660
+ borrowIncentiveIds.config,
5661
+ borrowIncentiveIds.incentivePools,
5662
+ borrowIncentiveIds.incentiveAccounts,
5663
+ obligationKey,
5664
+ obligationId,
5665
+ import_utils17.SUI_CLOCK_OBJECT_ID
5666
+ ],
5667
+ [rewardType]
5668
+ );
5669
+ },
5670
+ deactivateBoost: (obligation, veScaKey) => {
5671
+ return txBlock.moveCall(
5672
+ `${borrowIncentiveIds.borrowIncentivePkg}::user::deactivate_boost`,
5673
+ [
5674
+ borrowIncentiveIds.config,
5675
+ borrowIncentiveIds.incentivePools,
5676
+ borrowIncentiveIds.incentiveAccounts,
5677
+ obligation,
5678
+ veScaKey,
5679
+ import_utils17.SUI_CLOCK_OBJECT_ID
5680
+ ]
5681
+ );
5682
+ }
5683
+ };
5684
+ };
5685
+ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
5686
+ return {
5687
+ stakeObligationQuick: async (obligation, obligationKey) => {
5688
+ const {
5689
+ obligationId: obligationArg,
5690
+ obligationKey: obligationKeyArg,
5691
+ obligationLocked
5692
+ } = await requireObligationInfo2(
5693
+ builder,
5694
+ txBlock,
5695
+ obligation,
5696
+ obligationKey
5697
+ );
5698
+ const unstakeObligationBeforeStake = !!txBlock.txBlock.blockData.transactions.find(
5699
+ (txn) => txn.kind === "MoveCall" && (txn.target === `${OLD_BORROW_INCENTIVE_PROTOCOL_ID}::user::unstake` || txn.target === `${builder.address.get("borrowIncentive.id")}::user::unstake`)
5700
+ );
5701
+ if (!obligationLocked || unstakeObligationBeforeStake) {
5702
+ txBlock.stakeObligation(obligationArg, obligationKeyArg);
5703
+ }
5704
+ },
5705
+ stakeObligationWithVeScaQuick: async (obligation, obligationKey, veScaKey) => {
5706
+ const {
5707
+ obligationId: obligationArg,
5708
+ obligationKey: obligationKeyArg,
5709
+ obligationLocked
5710
+ } = await requireObligationInfo2(
5711
+ builder,
5712
+ txBlock,
5713
+ obligation,
5714
+ obligationKey
5715
+ );
5716
+ const unstakeObligationBeforeStake = !!txBlock.txBlock.blockData.transactions.find(
5717
+ (txn) => txn.kind === "MoveCall" && (txn.target === `${OLD_BORROW_INCENTIVE_PROTOCOL_ID}::user::unstake` || txn.target === `${builder.address.get("borrowIncentive.id")}::user::unstake`)
5718
+ );
5719
+ if (!obligationLocked || unstakeObligationBeforeStake) {
5720
+ const bindedVeScaKey = await builder.query.getBindedVeScaKey(obligationArg);
5721
+ if (veScaKey && veScaKey !== bindedVeScaKey || !bindedVeScaKey) {
5722
+ txBlock.stakeObligation(obligationArg, obligationKeyArg);
5723
+ } else {
5724
+ txBlock.stakeObligationWithVesca(
5725
+ obligationArg,
5726
+ obligationKeyArg,
5727
+ bindedVeScaKey
5728
+ );
5729
+ }
5730
+ }
5731
+ },
5732
+ unstakeObligationQuick: async (obligation, obligationKey) => {
5733
+ const {
5734
+ obligationId: obligationArg,
5735
+ obligationKey: obligationKeyArg,
5736
+ obligationLocked
5737
+ } = await requireObligationInfo2(
5738
+ builder,
5739
+ txBlock,
5740
+ obligation,
5741
+ obligationKey
5742
+ );
5743
+ if (obligationLocked) {
5744
+ txBlock.unstakeObligation(obligationArg, obligationKeyArg);
5745
+ }
5746
+ },
5747
+ claimBorrowIncentiveQuick: async (coinName, rewardCoinName, obligation, obligationKey) => {
5748
+ const { obligationId: obligationArg, obligationKey: obligationKeyArg } = await requireObligationInfo2(
5749
+ builder,
5750
+ txBlock,
5751
+ obligation,
5752
+ obligationKey
5753
+ );
5754
+ return txBlock.claimBorrowIncentive(
5755
+ obligationArg,
5756
+ obligationKeyArg,
5757
+ coinName,
5758
+ rewardCoinName
5759
+ );
5760
+ }
5761
+ };
5762
+ };
5763
+ var newBorrowIncentiveTxBlock = (builder, initTxBlock) => {
5764
+ const txBlock = initTxBlock instanceof import_transactions3.TransactionBlock ? new import_sui_kit7.SuiTxBlock(initTxBlock) : initTxBlock ? initTxBlock : new import_sui_kit7.SuiTxBlock();
5765
+ const normalMethod = generateBorrowIncentiveNormalMethod({
5766
+ builder,
5767
+ txBlock
5768
+ });
5769
+ const normalTxBlock = new Proxy(txBlock, {
5770
+ get: (target, prop) => {
5771
+ if (prop in normalMethod) {
5772
+ return Reflect.get(normalMethod, prop);
5773
+ }
5774
+ return Reflect.get(target, prop);
5775
+ }
5776
+ });
5777
+ const quickMethod = generateBorrowIncentiveQuickMethod({
5778
+ builder,
5779
+ txBlock: normalTxBlock
5780
+ });
5781
+ return new Proxy(normalTxBlock, {
5782
+ get: (target, prop) => {
5783
+ if (prop in quickMethod) {
5784
+ return Reflect.get(quickMethod, prop);
5785
+ }
5786
+ return Reflect.get(target, prop);
5787
+ }
5788
+ });
5789
+ };
5564
5790
 
5565
5791
  // src/builders/vescaBuilder.ts
5566
- var import_sui_kit7 = require("@scallop-io/sui-kit");
5792
+ var import_sui_kit8 = require("@scallop-io/sui-kit");
5567
5793
  var requireVeSca = async (...params) => {
5568
5794
  const [builder, txBlock, veScaKey] = params;
5569
5795
  if (params.length === 3 && veScaKey && typeof veScaKey === "string") {
@@ -5578,7 +5804,7 @@ var requireVeSca = async (...params) => {
5578
5804
  if (veScas.length === 0) {
5579
5805
  return void 0;
5580
5806
  }
5581
- return veScas[0];
5807
+ return veScaKey ? veScas.find(({ keyId }) => veScaKey === keyId) : veScas[0];
5582
5808
  };
5583
5809
  var generateNormalVeScaMethod = ({
5584
5810
  builder,
@@ -5600,7 +5826,7 @@ var generateNormalVeScaMethod = ({
5600
5826
  veScaIds.treasury,
5601
5827
  scaCoin,
5602
5828
  unlockAtInSecondTimestamp,
5603
- import_sui_kit7.SUI_CLOCK_OBJECT_ID
5829
+ import_sui_kit8.SUI_CLOCK_OBJECT_ID
5604
5830
  ],
5605
5831
  []
5606
5832
  );
@@ -5614,7 +5840,7 @@ var generateNormalVeScaMethod = ({
5614
5840
  veScaIds.table,
5615
5841
  veScaIds.treasury,
5616
5842
  newUnlockAtInSecondTimestamp,
5617
- import_sui_kit7.SUI_CLOCK_OBJECT_ID
5843
+ import_sui_kit8.SUI_CLOCK_OBJECT_ID
5618
5844
  ],
5619
5845
  []
5620
5846
  );
@@ -5628,7 +5854,7 @@ var generateNormalVeScaMethod = ({
5628
5854
  veScaIds.table,
5629
5855
  veScaIds.treasury,
5630
5856
  scaCoin,
5631
- import_sui_kit7.SUI_CLOCK_OBJECT_ID
5857
+ import_sui_kit8.SUI_CLOCK_OBJECT_ID
5632
5858
  ],
5633
5859
  []
5634
5860
  );
@@ -5643,7 +5869,7 @@ var generateNormalVeScaMethod = ({
5643
5869
  veScaIds.treasury,
5644
5870
  scaCoin,
5645
5871
  newUnlockAtInSecondTimestamp,
5646
- import_sui_kit7.SUI_CLOCK_OBJECT_ID
5872
+ import_sui_kit8.SUI_CLOCK_OBJECT_ID
5647
5873
  ],
5648
5874
  []
5649
5875
  );
@@ -5656,7 +5882,7 @@ var generateNormalVeScaMethod = ({
5656
5882
  veScaKey,
5657
5883
  veScaIds.table,
5658
5884
  veScaIds.treasury,
5659
- import_sui_kit7.SUI_CLOCK_OBJECT_ID
5885
+ import_sui_kit8.SUI_CLOCK_OBJECT_ID
5660
5886
  ],
5661
5887
  []
5662
5888
  );
@@ -5811,7 +6037,7 @@ var generateQuickVeScaMethod = ({
5811
6037
  };
5812
6038
  };
5813
6039
  var newVeScaTxBlock = (builder, initTxBlock) => {
5814
- const txBlock = initTxBlock instanceof import_sui_kit7.TransactionBlock ? new import_sui_kit7.SuiTxBlock(initTxBlock) : initTxBlock ? initTxBlock : new import_sui_kit7.SuiTxBlock();
6040
+ const txBlock = initTxBlock instanceof import_sui_kit8.TransactionBlock ? new import_sui_kit8.SuiTxBlock(initTxBlock) : initTxBlock ? initTxBlock : new import_sui_kit8.SuiTxBlock();
5815
6041
  const normalMethod = generateNormalVeScaMethod({
5816
6042
  builder,
5817
6043
  txBlock
@@ -5838,241 +6064,6 @@ var newVeScaTxBlock = (builder, initTxBlock) => {
5838
6064
  });
5839
6065
  };
5840
6066
 
5841
- // src/builders/borrowIncentiveBuilder.ts
5842
- var requireObligationInfo2 = async (...params) => {
5843
- const [builder, txBlock, obligationId, obligationKey] = params;
5844
- if (params.length === 4 && obligationId && obligationKey && typeof obligationId === "string") {
5845
- const obligationLocked = await getObligationLocked(
5846
- builder.cache,
5847
- obligationId
5848
- );
5849
- return { obligationId, obligationKey, obligationLocked };
5850
- }
5851
- const sender = requireSender(txBlock);
5852
- const obligations = await getObligations(builder, sender);
5853
- if (obligations.length === 0) {
5854
- throw new Error(`No obligation found for sender ${sender}`);
5855
- }
5856
- const selectedObligation = obligations.find(
5857
- (obligation) => obligation.id === obligationId || obligation.keyId === obligationKey
5858
- ) ?? obligations[0];
5859
- return {
5860
- obligationId: selectedObligation.id,
5861
- obligationKey: selectedObligation.keyId,
5862
- obligationLocked: selectedObligation.locked
5863
- };
5864
- };
5865
- var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
5866
- const borrowIncentiveIds = {
5867
- borrowIncentivePkg: builder.address.get("borrowIncentive.id"),
5868
- query: builder.address.get("borrowIncentive.query"),
5869
- config: builder.address.get("borrowIncentive.config"),
5870
- incentivePools: builder.address.get("borrowIncentive.incentivePools"),
5871
- incentiveAccounts: builder.address.get(
5872
- "borrowIncentive.incentiveAccounts"
5873
- ),
5874
- obligationAccessStore: builder.address.get("core.obligationAccessStore")
5875
- };
5876
- const veScaIds = {
5877
- table: builder.address.get("vesca.table"),
5878
- treasury: builder.address.get("vesca.treasury"),
5879
- config: builder.address.get("vesca.config")
5880
- };
5881
- return {
5882
- stakeObligation: (obligationId, obligationKey) => {
5883
- txBlock.moveCall(
5884
- `${borrowIncentiveIds.borrowIncentivePkg}::user::stake`,
5885
- [
5886
- borrowIncentiveIds.config,
5887
- borrowIncentiveIds.incentivePools,
5888
- borrowIncentiveIds.incentiveAccounts,
5889
- obligationKey,
5890
- obligationId,
5891
- borrowIncentiveIds.obligationAccessStore,
5892
- import_utils18.SUI_CLOCK_OBJECT_ID
5893
- ]
5894
- );
5895
- },
5896
- stakeObligationWithVesca: (obligationId, obligationKey, veScaKey) => {
5897
- txBlock.moveCall(
5898
- `${borrowIncentiveIds.borrowIncentivePkg}::user::stake_with_ve_sca`,
5899
- [
5900
- borrowIncentiveIds.config,
5901
- borrowIncentiveIds.incentivePools,
5902
- borrowIncentiveIds.incentiveAccounts,
5903
- obligationKey,
5904
- obligationId,
5905
- borrowIncentiveIds.obligationAccessStore,
5906
- veScaIds.config,
5907
- veScaIds.treasury,
5908
- veScaIds.table,
5909
- veScaKey,
5910
- import_utils18.SUI_CLOCK_OBJECT_ID
5911
- ],
5912
- []
5913
- );
5914
- },
5915
- unstakeObligation: (obligationId, obligationKey) => {
5916
- txBlock.moveCall(
5917
- `${borrowIncentiveIds.borrowIncentivePkg}::user::unstake`,
5918
- [
5919
- borrowIncentiveIds.config,
5920
- borrowIncentiveIds.incentivePools,
5921
- borrowIncentiveIds.incentiveAccounts,
5922
- obligationKey,
5923
- obligationId,
5924
- import_utils18.SUI_CLOCK_OBJECT_ID
5925
- ]
5926
- );
5927
- },
5928
- claimBorrowIncentive: (obligationId, obligationKey, coinName, rewardCoinName) => {
5929
- const rewardCoinNames = builder.utils.getBorrowIncentiveRewardCoinName(coinName);
5930
- if (rewardCoinNames.includes(rewardCoinName) === false) {
5931
- throw new Error(`Invalid reward coin name ${rewardCoinName}`);
5932
- }
5933
- const rewardType = builder.utils.parseCoinType(rewardCoinName);
5934
- return txBlock.moveCall(
5935
- `${borrowIncentiveIds.borrowIncentivePkg}::user::redeem_rewards`,
5936
- [
5937
- borrowIncentiveIds.config,
5938
- borrowIncentiveIds.incentivePools,
5939
- borrowIncentiveIds.incentiveAccounts,
5940
- obligationKey,
5941
- obligationId,
5942
- import_utils18.SUI_CLOCK_OBJECT_ID
5943
- ],
5944
- [rewardType]
5945
- );
5946
- },
5947
- deactivateBoost: (obligation, veScaKey) => {
5948
- return txBlock.moveCall(
5949
- `${borrowIncentiveIds.borrowIncentivePkg}::user::deactivate_boost`,
5950
- [
5951
- borrowIncentiveIds.config,
5952
- borrowIncentiveIds.incentivePools,
5953
- borrowIncentiveIds.incentiveAccounts,
5954
- obligation,
5955
- veScaKey,
5956
- import_utils18.SUI_CLOCK_OBJECT_ID
5957
- ]
5958
- );
5959
- }
5960
- };
5961
- };
5962
- var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
5963
- return {
5964
- stakeObligationQuick: async (obligation, obligationKey) => {
5965
- const {
5966
- obligationId: obligationArg,
5967
- obligationKey: obligationKeyArg,
5968
- obligationLocked
5969
- } = await requireObligationInfo2(
5970
- builder,
5971
- txBlock,
5972
- obligation,
5973
- obligationKey
5974
- );
5975
- const unstakeObligationBeforeStake = !!txBlock.txBlock.blockData.transactions.find(
5976
- (txn) => txn.kind === "MoveCall" && (txn.target === `${OLD_BORROW_INCENTIVE_PROTOCOL_ID}::user::unstake` || txn.target === `${builder.address.get("borrowIncentive.id")}::user::unstake`)
5977
- );
5978
- if (!obligationLocked || unstakeObligationBeforeStake) {
5979
- txBlock.stakeObligation(obligationArg, obligationKeyArg);
5980
- }
5981
- },
5982
- stakeObligationWithVeScaQuick: async (obligation, obligationKey, veScaKey) => {
5983
- const {
5984
- obligationId: obligationArg,
5985
- obligationKey: obligationKeyArg,
5986
- obligationLocked
5987
- } = await requireObligationInfo2(
5988
- builder,
5989
- txBlock,
5990
- obligation,
5991
- obligationKey
5992
- );
5993
- const unstakeObligationBeforeStake = !!txBlock.txBlock.blockData.transactions.find(
5994
- (txn) => txn.kind === "MoveCall" && (txn.target === `${OLD_BORROW_INCENTIVE_PROTOCOL_ID}::user::unstake` || txn.target === `${builder.address.get("borrowIncentive.id")}::user::unstake`)
5995
- );
5996
- if (!obligationLocked || unstakeObligationBeforeStake) {
5997
- const veSca = await requireVeSca(builder, txBlock, veScaKey);
5998
- if (veSca) {
5999
- const bindedObligationId = await getBindedObligationId(
6000
- builder,
6001
- veSca.keyId
6002
- );
6003
- if ((!bindedObligationId || bindedObligationId === obligationArg) && veSca.currentVeScaBalance > 0) {
6004
- txBlock.stakeObligationWithVesca(
6005
- obligationArg,
6006
- obligationKeyArg,
6007
- veSca.keyId
6008
- );
6009
- } else {
6010
- txBlock.stakeObligation(obligationArg, obligationKeyArg);
6011
- }
6012
- } else {
6013
- txBlock.stakeObligation(obligationArg, obligationKeyArg);
6014
- }
6015
- }
6016
- },
6017
- unstakeObligationQuick: async (obligation, obligationKey) => {
6018
- const {
6019
- obligationId: obligationArg,
6020
- obligationKey: obligationKeyArg,
6021
- obligationLocked
6022
- } = await requireObligationInfo2(
6023
- builder,
6024
- txBlock,
6025
- obligation,
6026
- obligationKey
6027
- );
6028
- if (obligationLocked) {
6029
- txBlock.unstakeObligation(obligationArg, obligationKeyArg);
6030
- }
6031
- },
6032
- claimBorrowIncentiveQuick: async (coinName, rewardCoinName, obligation, obligationKey) => {
6033
- const { obligationId: obligationArg, obligationKey: obligationKeyArg } = await requireObligationInfo2(
6034
- builder,
6035
- txBlock,
6036
- obligation,
6037
- obligationKey
6038
- );
6039
- return txBlock.claimBorrowIncentive(
6040
- obligationArg,
6041
- obligationKeyArg,
6042
- coinName,
6043
- rewardCoinName
6044
- );
6045
- }
6046
- };
6047
- };
6048
- var newBorrowIncentiveTxBlock = (builder, initTxBlock) => {
6049
- const txBlock = initTxBlock instanceof import_transactions3.TransactionBlock ? new import_sui_kit8.SuiTxBlock(initTxBlock) : initTxBlock ? initTxBlock : new import_sui_kit8.SuiTxBlock();
6050
- const normalMethod = generateBorrowIncentiveNormalMethod({
6051
- builder,
6052
- txBlock
6053
- });
6054
- const normalTxBlock = new Proxy(txBlock, {
6055
- get: (target, prop) => {
6056
- if (prop in normalMethod) {
6057
- return Reflect.get(normalMethod, prop);
6058
- }
6059
- return Reflect.get(target, prop);
6060
- }
6061
- });
6062
- const quickMethod = generateBorrowIncentiveQuickMethod({
6063
- builder,
6064
- txBlock: normalTxBlock
6065
- });
6066
- return new Proxy(normalTxBlock, {
6067
- get: (target, prop) => {
6068
- if (prop in quickMethod) {
6069
- return Reflect.get(quickMethod, prop);
6070
- }
6071
- return Reflect.get(target, prop);
6072
- }
6073
- });
6074
- };
6075
-
6076
6067
  // src/builders/referralBuilder.ts
6077
6068
  var import_sui_kit9 = require("@scallop-io/sui-kit");
6078
6069
  var generateReferralNormalMethod = ({
@@ -8000,11 +7991,15 @@ var Scallop = class {
8000
7991
  *
8001
7992
  * @return Scallop Builder.
8002
7993
  */
8003
- async createScallopBuilder() {
7994
+ async createScallopBuilder(params) {
8004
7995
  if (!this.address.getAddresses())
8005
7996
  await this.address.read();
8006
- const scallopBuilder = new ScallopBuilder(this.params, {
8007
- query: await this.createScallopQuery()
7997
+ const builderParams = {
7998
+ ...this.params,
7999
+ ...params
8000
+ };
8001
+ const scallopBuilder = new ScallopBuilder(builderParams, {
8002
+ query: await this.createScallopQuery(builderParams)
8008
8003
  });
8009
8004
  return scallopBuilder;
8010
8005
  }
@@ -8014,13 +8009,16 @@ var Scallop = class {
8014
8009
  * @param walletAddress - When user cannot provide a secret key or mnemonic, the scallop client cannot directly derive the address of the transaction the user wants to sign. This argument specifies the wallet address for signing the transaction.
8015
8010
  * @return Scallop Client.
8016
8011
  */
8017
- async createScallopClient(walletAddress) {
8012
+ async createScallopClient(params) {
8018
8013
  if (!this.address.getAddresses())
8019
8014
  await this.address.read();
8020
- const scallopClient = new ScallopClient(
8021
- { ...this.params, walletAddress },
8022
- { builder: await this.createScallopBuilder() }
8023
- );
8015
+ const clientParams = {
8016
+ ...this.params,
8017
+ ...params
8018
+ };
8019
+ const scallopClient = new ScallopClient(clientParams, {
8020
+ builder: await this.createScallopBuilder(clientParams)
8021
+ });
8024
8022
  return scallopClient;
8025
8023
  }
8026
8024
  /**
@@ -8028,11 +8026,15 @@ var Scallop = class {
8028
8026
  *
8029
8027
  * @return Scallop Query.
8030
8028
  */
8031
- async createScallopQuery() {
8029
+ async createScallopQuery(params) {
8032
8030
  if (!this.address.getAddresses())
8033
8031
  await this.address.read();
8034
- const scallopQuery = new ScallopQuery(this.params, {
8035
- utils: await this.createScallopUtils()
8032
+ const queryParams = {
8033
+ ...this.params,
8034
+ ...params
8035
+ };
8036
+ const scallopQuery = new ScallopQuery(queryParams, {
8037
+ utils: await this.createScallopUtils(queryParams)
8036
8038
  });
8037
8039
  return scallopQuery;
8038
8040
  }
@@ -8052,12 +8054,18 @@ var Scallop = class {
8052
8054
  *
8053
8055
  * @return Scallop Utils.
8054
8056
  */
8055
- async createScallopUtils() {
8057
+ async createScallopUtils(params) {
8056
8058
  if (!this.address.getAddresses())
8057
8059
  await this.address.read();
8058
- const scallopUtils = new ScallopUtils(this.params, {
8059
- address: this.address
8060
- });
8060
+ const scallopUtils = new ScallopUtils(
8061
+ {
8062
+ ...this.params,
8063
+ ...params
8064
+ },
8065
+ {
8066
+ address: this.address
8067
+ }
8068
+ );
8061
8069
  return scallopUtils;
8062
8070
  }
8063
8071
  };