@scallop-io/sui-scallop-sdk 0.47.0 → 0.47.2
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.js +253 -247
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +256 -250
- package/dist/index.mjs.map +1 -1
- package/dist/queries/borrowIncentiveQuery.d.ts +1 -1
- package/package.json +1 -1
- package/src/builders/borrowIncentiveBuilder.ts +14 -25
- package/src/builders/vescaBuilder.ts +2 -1
- package/src/queries/borrowIncentiveQuery.ts +2 -2
- package/src/queries/spoolQuery.ts +11 -0
package/dist/index.js
CHANGED
|
@@ -3234,6 +3234,17 @@ var getStakeAccounts = async ({
|
|
|
3234
3234
|
points,
|
|
3235
3235
|
totalPoints
|
|
3236
3236
|
});
|
|
3237
|
+
} else if ((0, import_utils5.normalizeStructTag)(type) === stakeMarketCoinTypes.susdc) {
|
|
3238
|
+
stakeAccounts.susdc.push({
|
|
3239
|
+
id,
|
|
3240
|
+
type: (0, import_utils5.normalizeStructTag)(type),
|
|
3241
|
+
stakePoolId,
|
|
3242
|
+
stakeType: (0, import_utils5.normalizeStructTag)(stakeType),
|
|
3243
|
+
staked,
|
|
3244
|
+
index,
|
|
3245
|
+
points,
|
|
3246
|
+
totalPoints
|
|
3247
|
+
});
|
|
3237
3248
|
}
|
|
3238
3249
|
}
|
|
3239
3250
|
}
|
|
@@ -3484,7 +3495,7 @@ var getBindedObligationId = async ({
|
|
|
3484
3495
|
};
|
|
3485
3496
|
var getBindedVeScaKey = async ({
|
|
3486
3497
|
address
|
|
3487
|
-
},
|
|
3498
|
+
}, obligationId) => {
|
|
3488
3499
|
const borrowIncentiveObjectId = address.get("borrowIncentive.object");
|
|
3489
3500
|
const incentiveAccountsId = address.get("borrowIncentive.incentiveAccounts");
|
|
3490
3501
|
const corePkg = address.get("core.object");
|
|
@@ -3501,7 +3512,7 @@ var getBindedVeScaKey = async ({
|
|
|
3501
3512
|
parentId: incentiveAccountsTableId,
|
|
3502
3513
|
name: {
|
|
3503
3514
|
type: `${borrowIncentiveObjectId}::typed_id::TypedID<${corePkg}::obligation::Obligation>`,
|
|
3504
|
-
value:
|
|
3515
|
+
value: obligationId
|
|
3505
3516
|
}
|
|
3506
3517
|
});
|
|
3507
3518
|
if (bindedIncentiveAcc?.data?.content?.dataType !== "moveObject")
|
|
@@ -5548,11 +5559,241 @@ var newSpoolTxBlock = (builder, initTxBlock) => {
|
|
|
5548
5559
|
|
|
5549
5560
|
// src/builders/borrowIncentiveBuilder.ts
|
|
5550
5561
|
var import_transactions3 = require("@mysten/sui.js/transactions");
|
|
5551
|
-
var
|
|
5552
|
-
var
|
|
5562
|
+
var import_utils17 = require("@mysten/sui.js/utils");
|
|
5563
|
+
var import_sui_kit7 = require("@scallop-io/sui-kit");
|
|
5564
|
+
var requireObligationInfo2 = async (...params) => {
|
|
5565
|
+
const [builder, txBlock, obligationId, obligationKey] = params;
|
|
5566
|
+
if (params.length === 4 && obligationId && obligationKey && typeof obligationId === "string") {
|
|
5567
|
+
const obligationLocked = await getObligationLocked(
|
|
5568
|
+
builder.cache,
|
|
5569
|
+
obligationId
|
|
5570
|
+
);
|
|
5571
|
+
return { obligationId, obligationKey, obligationLocked };
|
|
5572
|
+
}
|
|
5573
|
+
const sender = requireSender(txBlock);
|
|
5574
|
+
const obligations = await getObligations(builder, sender);
|
|
5575
|
+
if (obligations.length === 0) {
|
|
5576
|
+
throw new Error(`No obligation found for sender ${sender}`);
|
|
5577
|
+
}
|
|
5578
|
+
const selectedObligation = obligations.find(
|
|
5579
|
+
(obligation) => obligation.id === obligationId || obligation.keyId === obligationKey
|
|
5580
|
+
) ?? obligations[0];
|
|
5581
|
+
return {
|
|
5582
|
+
obligationId: selectedObligation.id,
|
|
5583
|
+
obligationKey: selectedObligation.keyId,
|
|
5584
|
+
obligationLocked: selectedObligation.locked
|
|
5585
|
+
};
|
|
5586
|
+
};
|
|
5587
|
+
var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
|
|
5588
|
+
const borrowIncentiveIds = {
|
|
5589
|
+
borrowIncentivePkg: builder.address.get("borrowIncentive.id"),
|
|
5590
|
+
query: builder.address.get("borrowIncentive.query"),
|
|
5591
|
+
config: builder.address.get("borrowIncentive.config"),
|
|
5592
|
+
incentivePools: builder.address.get("borrowIncentive.incentivePools"),
|
|
5593
|
+
incentiveAccounts: builder.address.get(
|
|
5594
|
+
"borrowIncentive.incentiveAccounts"
|
|
5595
|
+
),
|
|
5596
|
+
obligationAccessStore: builder.address.get("core.obligationAccessStore")
|
|
5597
|
+
};
|
|
5598
|
+
const veScaIds = {
|
|
5599
|
+
table: builder.address.get("vesca.table"),
|
|
5600
|
+
treasury: builder.address.get("vesca.treasury"),
|
|
5601
|
+
config: builder.address.get("vesca.config")
|
|
5602
|
+
};
|
|
5603
|
+
return {
|
|
5604
|
+
stakeObligation: (obligationId, obligationKey) => {
|
|
5605
|
+
txBlock.moveCall(
|
|
5606
|
+
`${borrowIncentiveIds.borrowIncentivePkg}::user::stake`,
|
|
5607
|
+
[
|
|
5608
|
+
borrowIncentiveIds.config,
|
|
5609
|
+
borrowIncentiveIds.incentivePools,
|
|
5610
|
+
borrowIncentiveIds.incentiveAccounts,
|
|
5611
|
+
obligationKey,
|
|
5612
|
+
obligationId,
|
|
5613
|
+
borrowIncentiveIds.obligationAccessStore,
|
|
5614
|
+
import_utils17.SUI_CLOCK_OBJECT_ID
|
|
5615
|
+
]
|
|
5616
|
+
);
|
|
5617
|
+
},
|
|
5618
|
+
stakeObligationWithVesca: (obligationId, obligationKey, veScaKey) => {
|
|
5619
|
+
txBlock.moveCall(
|
|
5620
|
+
`${borrowIncentiveIds.borrowIncentivePkg}::user::stake_with_ve_sca`,
|
|
5621
|
+
[
|
|
5622
|
+
borrowIncentiveIds.config,
|
|
5623
|
+
borrowIncentiveIds.incentivePools,
|
|
5624
|
+
borrowIncentiveIds.incentiveAccounts,
|
|
5625
|
+
obligationKey,
|
|
5626
|
+
obligationId,
|
|
5627
|
+
borrowIncentiveIds.obligationAccessStore,
|
|
5628
|
+
veScaIds.config,
|
|
5629
|
+
veScaIds.treasury,
|
|
5630
|
+
veScaIds.table,
|
|
5631
|
+
veScaKey,
|
|
5632
|
+
import_utils17.SUI_CLOCK_OBJECT_ID
|
|
5633
|
+
],
|
|
5634
|
+
[]
|
|
5635
|
+
);
|
|
5636
|
+
},
|
|
5637
|
+
unstakeObligation: (obligationId, obligationKey) => {
|
|
5638
|
+
txBlock.moveCall(
|
|
5639
|
+
`${borrowIncentiveIds.borrowIncentivePkg}::user::unstake`,
|
|
5640
|
+
[
|
|
5641
|
+
borrowIncentiveIds.config,
|
|
5642
|
+
borrowIncentiveIds.incentivePools,
|
|
5643
|
+
borrowIncentiveIds.incentiveAccounts,
|
|
5644
|
+
obligationKey,
|
|
5645
|
+
obligationId,
|
|
5646
|
+
import_utils17.SUI_CLOCK_OBJECT_ID
|
|
5647
|
+
]
|
|
5648
|
+
);
|
|
5649
|
+
},
|
|
5650
|
+
claimBorrowIncentive: (obligationId, obligationKey, coinName, rewardCoinName) => {
|
|
5651
|
+
const rewardCoinNames = builder.utils.getBorrowIncentiveRewardCoinName(coinName);
|
|
5652
|
+
if (rewardCoinNames.includes(rewardCoinName) === false) {
|
|
5653
|
+
throw new Error(`Invalid reward coin name ${rewardCoinName}`);
|
|
5654
|
+
}
|
|
5655
|
+
const rewardType = builder.utils.parseCoinType(rewardCoinName);
|
|
5656
|
+
return txBlock.moveCall(
|
|
5657
|
+
`${borrowIncentiveIds.borrowIncentivePkg}::user::redeem_rewards`,
|
|
5658
|
+
[
|
|
5659
|
+
borrowIncentiveIds.config,
|
|
5660
|
+
borrowIncentiveIds.incentivePools,
|
|
5661
|
+
borrowIncentiveIds.incentiveAccounts,
|
|
5662
|
+
obligationKey,
|
|
5663
|
+
obligationId,
|
|
5664
|
+
import_utils17.SUI_CLOCK_OBJECT_ID
|
|
5665
|
+
],
|
|
5666
|
+
[rewardType]
|
|
5667
|
+
);
|
|
5668
|
+
},
|
|
5669
|
+
deactivateBoost: (obligation, veScaKey) => {
|
|
5670
|
+
return txBlock.moveCall(
|
|
5671
|
+
`${borrowIncentiveIds.borrowIncentivePkg}::user::deactivate_boost`,
|
|
5672
|
+
[
|
|
5673
|
+
borrowIncentiveIds.config,
|
|
5674
|
+
borrowIncentiveIds.incentivePools,
|
|
5675
|
+
borrowIncentiveIds.incentiveAccounts,
|
|
5676
|
+
obligation,
|
|
5677
|
+
veScaKey,
|
|
5678
|
+
import_utils17.SUI_CLOCK_OBJECT_ID
|
|
5679
|
+
]
|
|
5680
|
+
);
|
|
5681
|
+
}
|
|
5682
|
+
};
|
|
5683
|
+
};
|
|
5684
|
+
var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
|
|
5685
|
+
return {
|
|
5686
|
+
stakeObligationQuick: async (obligation, obligationKey) => {
|
|
5687
|
+
const {
|
|
5688
|
+
obligationId: obligationArg,
|
|
5689
|
+
obligationKey: obligationKeyArg,
|
|
5690
|
+
obligationLocked
|
|
5691
|
+
} = await requireObligationInfo2(
|
|
5692
|
+
builder,
|
|
5693
|
+
txBlock,
|
|
5694
|
+
obligation,
|
|
5695
|
+
obligationKey
|
|
5696
|
+
);
|
|
5697
|
+
const unstakeObligationBeforeStake = !!txBlock.txBlock.blockData.transactions.find(
|
|
5698
|
+
(txn) => txn.kind === "MoveCall" && (txn.target === `${OLD_BORROW_INCENTIVE_PROTOCOL_ID}::user::unstake` || txn.target === `${builder.address.get("borrowIncentive.id")}::user::unstake`)
|
|
5699
|
+
);
|
|
5700
|
+
if (!obligationLocked || unstakeObligationBeforeStake) {
|
|
5701
|
+
txBlock.stakeObligation(obligationArg, obligationKeyArg);
|
|
5702
|
+
}
|
|
5703
|
+
},
|
|
5704
|
+
stakeObligationWithVeScaQuick: async (obligation, obligationKey, veScaKey) => {
|
|
5705
|
+
const {
|
|
5706
|
+
obligationId: obligationArg,
|
|
5707
|
+
obligationKey: obligationKeyArg,
|
|
5708
|
+
obligationLocked
|
|
5709
|
+
} = await requireObligationInfo2(
|
|
5710
|
+
builder,
|
|
5711
|
+
txBlock,
|
|
5712
|
+
obligation,
|
|
5713
|
+
obligationKey
|
|
5714
|
+
);
|
|
5715
|
+
const unstakeObligationBeforeStake = !!txBlock.txBlock.blockData.transactions.find(
|
|
5716
|
+
(txn) => txn.kind === "MoveCall" && (txn.target === `${OLD_BORROW_INCENTIVE_PROTOCOL_ID}::user::unstake` || txn.target === `${builder.address.get("borrowIncentive.id")}::user::unstake`)
|
|
5717
|
+
);
|
|
5718
|
+
if (!obligationLocked || unstakeObligationBeforeStake) {
|
|
5719
|
+
const bindedVeScaKey = await builder.query.getBindedVeScaKey(obligationArg);
|
|
5720
|
+
if (veScaKey && veScaKey !== bindedVeScaKey) {
|
|
5721
|
+
throw new Error(
|
|
5722
|
+
"Binded veScaKey is not equal to the provided veScaKey"
|
|
5723
|
+
);
|
|
5724
|
+
}
|
|
5725
|
+
if (bindedVeScaKey) {
|
|
5726
|
+
txBlock.stakeObligationWithVesca(
|
|
5727
|
+
obligationArg,
|
|
5728
|
+
obligationKeyArg,
|
|
5729
|
+
bindedVeScaKey
|
|
5730
|
+
);
|
|
5731
|
+
} else {
|
|
5732
|
+
txBlock.stakeObligation(obligationArg, obligationKeyArg);
|
|
5733
|
+
}
|
|
5734
|
+
}
|
|
5735
|
+
},
|
|
5736
|
+
unstakeObligationQuick: async (obligation, obligationKey) => {
|
|
5737
|
+
const {
|
|
5738
|
+
obligationId: obligationArg,
|
|
5739
|
+
obligationKey: obligationKeyArg,
|
|
5740
|
+
obligationLocked
|
|
5741
|
+
} = await requireObligationInfo2(
|
|
5742
|
+
builder,
|
|
5743
|
+
txBlock,
|
|
5744
|
+
obligation,
|
|
5745
|
+
obligationKey
|
|
5746
|
+
);
|
|
5747
|
+
if (obligationLocked) {
|
|
5748
|
+
txBlock.unstakeObligation(obligationArg, obligationKeyArg);
|
|
5749
|
+
}
|
|
5750
|
+
},
|
|
5751
|
+
claimBorrowIncentiveQuick: async (coinName, rewardCoinName, obligation, obligationKey) => {
|
|
5752
|
+
const { obligationId: obligationArg, obligationKey: obligationKeyArg } = await requireObligationInfo2(
|
|
5753
|
+
builder,
|
|
5754
|
+
txBlock,
|
|
5755
|
+
obligation,
|
|
5756
|
+
obligationKey
|
|
5757
|
+
);
|
|
5758
|
+
return txBlock.claimBorrowIncentive(
|
|
5759
|
+
obligationArg,
|
|
5760
|
+
obligationKeyArg,
|
|
5761
|
+
coinName,
|
|
5762
|
+
rewardCoinName
|
|
5763
|
+
);
|
|
5764
|
+
}
|
|
5765
|
+
};
|
|
5766
|
+
};
|
|
5767
|
+
var newBorrowIncentiveTxBlock = (builder, initTxBlock) => {
|
|
5768
|
+
const txBlock = initTxBlock instanceof import_transactions3.TransactionBlock ? new import_sui_kit7.SuiTxBlock(initTxBlock) : initTxBlock ? initTxBlock : new import_sui_kit7.SuiTxBlock();
|
|
5769
|
+
const normalMethod = generateBorrowIncentiveNormalMethod({
|
|
5770
|
+
builder,
|
|
5771
|
+
txBlock
|
|
5772
|
+
});
|
|
5773
|
+
const normalTxBlock = new Proxy(txBlock, {
|
|
5774
|
+
get: (target, prop) => {
|
|
5775
|
+
if (prop in normalMethod) {
|
|
5776
|
+
return Reflect.get(normalMethod, prop);
|
|
5777
|
+
}
|
|
5778
|
+
return Reflect.get(target, prop);
|
|
5779
|
+
}
|
|
5780
|
+
});
|
|
5781
|
+
const quickMethod = generateBorrowIncentiveQuickMethod({
|
|
5782
|
+
builder,
|
|
5783
|
+
txBlock: normalTxBlock
|
|
5784
|
+
});
|
|
5785
|
+
return new Proxy(normalTxBlock, {
|
|
5786
|
+
get: (target, prop) => {
|
|
5787
|
+
if (prop in quickMethod) {
|
|
5788
|
+
return Reflect.get(quickMethod, prop);
|
|
5789
|
+
}
|
|
5790
|
+
return Reflect.get(target, prop);
|
|
5791
|
+
}
|
|
5792
|
+
});
|
|
5793
|
+
};
|
|
5553
5794
|
|
|
5554
5795
|
// src/builders/vescaBuilder.ts
|
|
5555
|
-
var
|
|
5796
|
+
var import_sui_kit8 = require("@scallop-io/sui-kit");
|
|
5556
5797
|
var requireVeSca = async (...params) => {
|
|
5557
5798
|
const [builder, txBlock, veScaKey] = params;
|
|
5558
5799
|
if (params.length === 3 && veScaKey && typeof veScaKey === "string") {
|
|
@@ -5567,7 +5808,7 @@ var requireVeSca = async (...params) => {
|
|
|
5567
5808
|
if (veScas.length === 0) {
|
|
5568
5809
|
return void 0;
|
|
5569
5810
|
}
|
|
5570
|
-
return veScas[0];
|
|
5811
|
+
return veScaKey ? veScas.find(({ keyId }) => veScaKey === keyId) : veScas[0];
|
|
5571
5812
|
};
|
|
5572
5813
|
var generateNormalVeScaMethod = ({
|
|
5573
5814
|
builder,
|
|
@@ -5589,7 +5830,7 @@ var generateNormalVeScaMethod = ({
|
|
|
5589
5830
|
veScaIds.treasury,
|
|
5590
5831
|
scaCoin,
|
|
5591
5832
|
unlockAtInSecondTimestamp,
|
|
5592
|
-
|
|
5833
|
+
import_sui_kit8.SUI_CLOCK_OBJECT_ID
|
|
5593
5834
|
],
|
|
5594
5835
|
[]
|
|
5595
5836
|
);
|
|
@@ -5603,7 +5844,7 @@ var generateNormalVeScaMethod = ({
|
|
|
5603
5844
|
veScaIds.table,
|
|
5604
5845
|
veScaIds.treasury,
|
|
5605
5846
|
newUnlockAtInSecondTimestamp,
|
|
5606
|
-
|
|
5847
|
+
import_sui_kit8.SUI_CLOCK_OBJECT_ID
|
|
5607
5848
|
],
|
|
5608
5849
|
[]
|
|
5609
5850
|
);
|
|
@@ -5617,7 +5858,7 @@ var generateNormalVeScaMethod = ({
|
|
|
5617
5858
|
veScaIds.table,
|
|
5618
5859
|
veScaIds.treasury,
|
|
5619
5860
|
scaCoin,
|
|
5620
|
-
|
|
5861
|
+
import_sui_kit8.SUI_CLOCK_OBJECT_ID
|
|
5621
5862
|
],
|
|
5622
5863
|
[]
|
|
5623
5864
|
);
|
|
@@ -5632,7 +5873,7 @@ var generateNormalVeScaMethod = ({
|
|
|
5632
5873
|
veScaIds.treasury,
|
|
5633
5874
|
scaCoin,
|
|
5634
5875
|
newUnlockAtInSecondTimestamp,
|
|
5635
|
-
|
|
5876
|
+
import_sui_kit8.SUI_CLOCK_OBJECT_ID
|
|
5636
5877
|
],
|
|
5637
5878
|
[]
|
|
5638
5879
|
);
|
|
@@ -5645,7 +5886,7 @@ var generateNormalVeScaMethod = ({
|
|
|
5645
5886
|
veScaKey,
|
|
5646
5887
|
veScaIds.table,
|
|
5647
5888
|
veScaIds.treasury,
|
|
5648
|
-
|
|
5889
|
+
import_sui_kit8.SUI_CLOCK_OBJECT_ID
|
|
5649
5890
|
],
|
|
5650
5891
|
[]
|
|
5651
5892
|
);
|
|
@@ -5800,7 +6041,7 @@ var generateQuickVeScaMethod = ({
|
|
|
5800
6041
|
};
|
|
5801
6042
|
};
|
|
5802
6043
|
var newVeScaTxBlock = (builder, initTxBlock) => {
|
|
5803
|
-
const txBlock = initTxBlock instanceof
|
|
6044
|
+
const txBlock = initTxBlock instanceof import_sui_kit8.TransactionBlock ? new import_sui_kit8.SuiTxBlock(initTxBlock) : initTxBlock ? initTxBlock : new import_sui_kit8.SuiTxBlock();
|
|
5804
6045
|
const normalMethod = generateNormalVeScaMethod({
|
|
5805
6046
|
builder,
|
|
5806
6047
|
txBlock
|
|
@@ -5827,241 +6068,6 @@ var newVeScaTxBlock = (builder, initTxBlock) => {
|
|
|
5827
6068
|
});
|
|
5828
6069
|
};
|
|
5829
6070
|
|
|
5830
|
-
// src/builders/borrowIncentiveBuilder.ts
|
|
5831
|
-
var requireObligationInfo2 = async (...params) => {
|
|
5832
|
-
const [builder, txBlock, obligationId, obligationKey] = params;
|
|
5833
|
-
if (params.length === 4 && obligationId && obligationKey && typeof obligationId === "string") {
|
|
5834
|
-
const obligationLocked = await getObligationLocked(
|
|
5835
|
-
builder.cache,
|
|
5836
|
-
obligationId
|
|
5837
|
-
);
|
|
5838
|
-
return { obligationId, obligationKey, obligationLocked };
|
|
5839
|
-
}
|
|
5840
|
-
const sender = requireSender(txBlock);
|
|
5841
|
-
const obligations = await getObligations(builder, sender);
|
|
5842
|
-
if (obligations.length === 0) {
|
|
5843
|
-
throw new Error(`No obligation found for sender ${sender}`);
|
|
5844
|
-
}
|
|
5845
|
-
const selectedObligation = obligations.find(
|
|
5846
|
-
(obligation) => obligation.id === obligationId || obligation.keyId === obligationKey
|
|
5847
|
-
) ?? obligations[0];
|
|
5848
|
-
return {
|
|
5849
|
-
obligationId: selectedObligation.id,
|
|
5850
|
-
obligationKey: selectedObligation.keyId,
|
|
5851
|
-
obligationLocked: selectedObligation.locked
|
|
5852
|
-
};
|
|
5853
|
-
};
|
|
5854
|
-
var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
|
|
5855
|
-
const borrowIncentiveIds = {
|
|
5856
|
-
borrowIncentivePkg: builder.address.get("borrowIncentive.id"),
|
|
5857
|
-
query: builder.address.get("borrowIncentive.query"),
|
|
5858
|
-
config: builder.address.get("borrowIncentive.config"),
|
|
5859
|
-
incentivePools: builder.address.get("borrowIncentive.incentivePools"),
|
|
5860
|
-
incentiveAccounts: builder.address.get(
|
|
5861
|
-
"borrowIncentive.incentiveAccounts"
|
|
5862
|
-
),
|
|
5863
|
-
obligationAccessStore: builder.address.get("core.obligationAccessStore")
|
|
5864
|
-
};
|
|
5865
|
-
const veScaIds = {
|
|
5866
|
-
table: builder.address.get("vesca.table"),
|
|
5867
|
-
treasury: builder.address.get("vesca.treasury"),
|
|
5868
|
-
config: builder.address.get("vesca.config")
|
|
5869
|
-
};
|
|
5870
|
-
return {
|
|
5871
|
-
stakeObligation: (obligationId, obligationKey) => {
|
|
5872
|
-
txBlock.moveCall(
|
|
5873
|
-
`${borrowIncentiveIds.borrowIncentivePkg}::user::stake`,
|
|
5874
|
-
[
|
|
5875
|
-
borrowIncentiveIds.config,
|
|
5876
|
-
borrowIncentiveIds.incentivePools,
|
|
5877
|
-
borrowIncentiveIds.incentiveAccounts,
|
|
5878
|
-
obligationKey,
|
|
5879
|
-
obligationId,
|
|
5880
|
-
borrowIncentiveIds.obligationAccessStore,
|
|
5881
|
-
import_utils18.SUI_CLOCK_OBJECT_ID
|
|
5882
|
-
]
|
|
5883
|
-
);
|
|
5884
|
-
},
|
|
5885
|
-
stakeObligationWithVesca: (obligationId, obligationKey, veScaKey) => {
|
|
5886
|
-
txBlock.moveCall(
|
|
5887
|
-
`${borrowIncentiveIds.borrowIncentivePkg}::user::stake_with_ve_sca`,
|
|
5888
|
-
[
|
|
5889
|
-
borrowIncentiveIds.config,
|
|
5890
|
-
borrowIncentiveIds.incentivePools,
|
|
5891
|
-
borrowIncentiveIds.incentiveAccounts,
|
|
5892
|
-
obligationKey,
|
|
5893
|
-
obligationId,
|
|
5894
|
-
borrowIncentiveIds.obligationAccessStore,
|
|
5895
|
-
veScaIds.config,
|
|
5896
|
-
veScaIds.treasury,
|
|
5897
|
-
veScaIds.table,
|
|
5898
|
-
veScaKey,
|
|
5899
|
-
import_utils18.SUI_CLOCK_OBJECT_ID
|
|
5900
|
-
],
|
|
5901
|
-
[]
|
|
5902
|
-
);
|
|
5903
|
-
},
|
|
5904
|
-
unstakeObligation: (obligationId, obligationKey) => {
|
|
5905
|
-
txBlock.moveCall(
|
|
5906
|
-
`${borrowIncentiveIds.borrowIncentivePkg}::user::unstake`,
|
|
5907
|
-
[
|
|
5908
|
-
borrowIncentiveIds.config,
|
|
5909
|
-
borrowIncentiveIds.incentivePools,
|
|
5910
|
-
borrowIncentiveIds.incentiveAccounts,
|
|
5911
|
-
obligationKey,
|
|
5912
|
-
obligationId,
|
|
5913
|
-
import_utils18.SUI_CLOCK_OBJECT_ID
|
|
5914
|
-
]
|
|
5915
|
-
);
|
|
5916
|
-
},
|
|
5917
|
-
claimBorrowIncentive: (obligationId, obligationKey, coinName, rewardCoinName) => {
|
|
5918
|
-
const rewardCoinNames = builder.utils.getBorrowIncentiveRewardCoinName(coinName);
|
|
5919
|
-
if (rewardCoinNames.includes(rewardCoinName) === false) {
|
|
5920
|
-
throw new Error(`Invalid reward coin name ${rewardCoinName}`);
|
|
5921
|
-
}
|
|
5922
|
-
const rewardType = builder.utils.parseCoinType(rewardCoinName);
|
|
5923
|
-
return txBlock.moveCall(
|
|
5924
|
-
`${borrowIncentiveIds.borrowIncentivePkg}::user::redeem_rewards`,
|
|
5925
|
-
[
|
|
5926
|
-
borrowIncentiveIds.config,
|
|
5927
|
-
borrowIncentiveIds.incentivePools,
|
|
5928
|
-
borrowIncentiveIds.incentiveAccounts,
|
|
5929
|
-
obligationKey,
|
|
5930
|
-
obligationId,
|
|
5931
|
-
import_utils18.SUI_CLOCK_OBJECT_ID
|
|
5932
|
-
],
|
|
5933
|
-
[rewardType]
|
|
5934
|
-
);
|
|
5935
|
-
},
|
|
5936
|
-
deactivateBoost: (obligation, veScaKey) => {
|
|
5937
|
-
return txBlock.moveCall(
|
|
5938
|
-
`${borrowIncentiveIds.borrowIncentivePkg}::user::deactivate_boost`,
|
|
5939
|
-
[
|
|
5940
|
-
borrowIncentiveIds.config,
|
|
5941
|
-
borrowIncentiveIds.incentivePools,
|
|
5942
|
-
borrowIncentiveIds.incentiveAccounts,
|
|
5943
|
-
obligation,
|
|
5944
|
-
veScaKey,
|
|
5945
|
-
import_utils18.SUI_CLOCK_OBJECT_ID
|
|
5946
|
-
]
|
|
5947
|
-
);
|
|
5948
|
-
}
|
|
5949
|
-
};
|
|
5950
|
-
};
|
|
5951
|
-
var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
|
|
5952
|
-
return {
|
|
5953
|
-
stakeObligationQuick: async (obligation, obligationKey) => {
|
|
5954
|
-
const {
|
|
5955
|
-
obligationId: obligationArg,
|
|
5956
|
-
obligationKey: obligationKeyArg,
|
|
5957
|
-
obligationLocked
|
|
5958
|
-
} = await requireObligationInfo2(
|
|
5959
|
-
builder,
|
|
5960
|
-
txBlock,
|
|
5961
|
-
obligation,
|
|
5962
|
-
obligationKey
|
|
5963
|
-
);
|
|
5964
|
-
const unstakeObligationBeforeStake = !!txBlock.txBlock.blockData.transactions.find(
|
|
5965
|
-
(txn) => txn.kind === "MoveCall" && (txn.target === `${OLD_BORROW_INCENTIVE_PROTOCOL_ID}::user::unstake` || txn.target === `${builder.address.get("borrowIncentive.id")}::user::unstake`)
|
|
5966
|
-
);
|
|
5967
|
-
if (!obligationLocked || unstakeObligationBeforeStake) {
|
|
5968
|
-
txBlock.stakeObligation(obligationArg, obligationKeyArg);
|
|
5969
|
-
}
|
|
5970
|
-
},
|
|
5971
|
-
stakeObligationWithVeScaQuick: async (obligation, obligationKey, veScaKey) => {
|
|
5972
|
-
const {
|
|
5973
|
-
obligationId: obligationArg,
|
|
5974
|
-
obligationKey: obligationKeyArg,
|
|
5975
|
-
obligationLocked
|
|
5976
|
-
} = await requireObligationInfo2(
|
|
5977
|
-
builder,
|
|
5978
|
-
txBlock,
|
|
5979
|
-
obligation,
|
|
5980
|
-
obligationKey
|
|
5981
|
-
);
|
|
5982
|
-
const unstakeObligationBeforeStake = !!txBlock.txBlock.blockData.transactions.find(
|
|
5983
|
-
(txn) => txn.kind === "MoveCall" && (txn.target === `${OLD_BORROW_INCENTIVE_PROTOCOL_ID}::user::unstake` || txn.target === `${builder.address.get("borrowIncentive.id")}::user::unstake`)
|
|
5984
|
-
);
|
|
5985
|
-
if (!obligationLocked || unstakeObligationBeforeStake) {
|
|
5986
|
-
const veSca = await requireVeSca(builder, txBlock, veScaKey);
|
|
5987
|
-
if (veSca) {
|
|
5988
|
-
const bindedObligationId = await getBindedObligationId(
|
|
5989
|
-
builder,
|
|
5990
|
-
veSca.keyId
|
|
5991
|
-
);
|
|
5992
|
-
if ((!bindedObligationId || bindedObligationId === obligationArg) && veSca.currentVeScaBalance > 0) {
|
|
5993
|
-
txBlock.stakeObligationWithVesca(
|
|
5994
|
-
obligationArg,
|
|
5995
|
-
obligationKeyArg,
|
|
5996
|
-
veSca.keyId
|
|
5997
|
-
);
|
|
5998
|
-
} else {
|
|
5999
|
-
txBlock.stakeObligation(obligationArg, obligationKeyArg);
|
|
6000
|
-
}
|
|
6001
|
-
} else {
|
|
6002
|
-
txBlock.stakeObligation(obligationArg, obligationKeyArg);
|
|
6003
|
-
}
|
|
6004
|
-
}
|
|
6005
|
-
},
|
|
6006
|
-
unstakeObligationQuick: async (obligation, obligationKey) => {
|
|
6007
|
-
const {
|
|
6008
|
-
obligationId: obligationArg,
|
|
6009
|
-
obligationKey: obligationKeyArg,
|
|
6010
|
-
obligationLocked
|
|
6011
|
-
} = await requireObligationInfo2(
|
|
6012
|
-
builder,
|
|
6013
|
-
txBlock,
|
|
6014
|
-
obligation,
|
|
6015
|
-
obligationKey
|
|
6016
|
-
);
|
|
6017
|
-
if (obligationLocked) {
|
|
6018
|
-
txBlock.unstakeObligation(obligationArg, obligationKeyArg);
|
|
6019
|
-
}
|
|
6020
|
-
},
|
|
6021
|
-
claimBorrowIncentiveQuick: async (coinName, rewardCoinName, obligation, obligationKey) => {
|
|
6022
|
-
const { obligationId: obligationArg, obligationKey: obligationKeyArg } = await requireObligationInfo2(
|
|
6023
|
-
builder,
|
|
6024
|
-
txBlock,
|
|
6025
|
-
obligation,
|
|
6026
|
-
obligationKey
|
|
6027
|
-
);
|
|
6028
|
-
return txBlock.claimBorrowIncentive(
|
|
6029
|
-
obligationArg,
|
|
6030
|
-
obligationKeyArg,
|
|
6031
|
-
coinName,
|
|
6032
|
-
rewardCoinName
|
|
6033
|
-
);
|
|
6034
|
-
}
|
|
6035
|
-
};
|
|
6036
|
-
};
|
|
6037
|
-
var newBorrowIncentiveTxBlock = (builder, initTxBlock) => {
|
|
6038
|
-
const txBlock = initTxBlock instanceof import_transactions3.TransactionBlock ? new import_sui_kit8.SuiTxBlock(initTxBlock) : initTxBlock ? initTxBlock : new import_sui_kit8.SuiTxBlock();
|
|
6039
|
-
const normalMethod = generateBorrowIncentiveNormalMethod({
|
|
6040
|
-
builder,
|
|
6041
|
-
txBlock
|
|
6042
|
-
});
|
|
6043
|
-
const normalTxBlock = new Proxy(txBlock, {
|
|
6044
|
-
get: (target, prop) => {
|
|
6045
|
-
if (prop in normalMethod) {
|
|
6046
|
-
return Reflect.get(normalMethod, prop);
|
|
6047
|
-
}
|
|
6048
|
-
return Reflect.get(target, prop);
|
|
6049
|
-
}
|
|
6050
|
-
});
|
|
6051
|
-
const quickMethod = generateBorrowIncentiveQuickMethod({
|
|
6052
|
-
builder,
|
|
6053
|
-
txBlock: normalTxBlock
|
|
6054
|
-
});
|
|
6055
|
-
return new Proxy(normalTxBlock, {
|
|
6056
|
-
get: (target, prop) => {
|
|
6057
|
-
if (prop in quickMethod) {
|
|
6058
|
-
return Reflect.get(quickMethod, prop);
|
|
6059
|
-
}
|
|
6060
|
-
return Reflect.get(target, prop);
|
|
6061
|
-
}
|
|
6062
|
-
});
|
|
6063
|
-
};
|
|
6064
|
-
|
|
6065
6071
|
// src/builders/referralBuilder.ts
|
|
6066
6072
|
var import_sui_kit9 = require("@scallop-io/sui-kit");
|
|
6067
6073
|
var generateReferralNormalMethod = ({
|