@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.mjs
CHANGED
|
@@ -3160,6 +3160,17 @@ var getStakeAccounts = async ({
|
|
|
3160
3160
|
points,
|
|
3161
3161
|
totalPoints
|
|
3162
3162
|
});
|
|
3163
|
+
} else if (normalizeStructTag4(type) === stakeMarketCoinTypes.susdc) {
|
|
3164
|
+
stakeAccounts.susdc.push({
|
|
3165
|
+
id,
|
|
3166
|
+
type: normalizeStructTag4(type),
|
|
3167
|
+
stakePoolId,
|
|
3168
|
+
stakeType: normalizeStructTag4(stakeType),
|
|
3169
|
+
staked,
|
|
3170
|
+
index,
|
|
3171
|
+
points,
|
|
3172
|
+
totalPoints
|
|
3173
|
+
});
|
|
3163
3174
|
}
|
|
3164
3175
|
}
|
|
3165
3176
|
}
|
|
@@ -3410,7 +3421,7 @@ var getBindedObligationId = async ({
|
|
|
3410
3421
|
};
|
|
3411
3422
|
var getBindedVeScaKey = async ({
|
|
3412
3423
|
address
|
|
3413
|
-
},
|
|
3424
|
+
}, obligationId) => {
|
|
3414
3425
|
const borrowIncentiveObjectId = address.get("borrowIncentive.object");
|
|
3415
3426
|
const incentiveAccountsId = address.get("borrowIncentive.incentiveAccounts");
|
|
3416
3427
|
const corePkg = address.get("core.object");
|
|
@@ -3427,7 +3438,7 @@ var getBindedVeScaKey = async ({
|
|
|
3427
3438
|
parentId: incentiveAccountsTableId,
|
|
3428
3439
|
name: {
|
|
3429
3440
|
type: `${borrowIncentiveObjectId}::typed_id::TypedID<${corePkg}::obligation::Obligation>`,
|
|
3430
|
-
value:
|
|
3441
|
+
value: obligationId
|
|
3431
3442
|
}
|
|
3432
3443
|
});
|
|
3433
3444
|
if (bindedIncentiveAcc?.data?.content?.dataType !== "moveObject")
|
|
@@ -5476,15 +5487,245 @@ var newSpoolTxBlock = (builder, initTxBlock) => {
|
|
|
5476
5487
|
};
|
|
5477
5488
|
|
|
5478
5489
|
// src/builders/borrowIncentiveBuilder.ts
|
|
5479
|
-
import { TransactionBlock as
|
|
5480
|
-
import { SUI_CLOCK_OBJECT_ID as
|
|
5481
|
-
import { SuiTxBlock as
|
|
5490
|
+
import { TransactionBlock as TransactionBlock3 } from "@mysten/sui.js/transactions";
|
|
5491
|
+
import { SUI_CLOCK_OBJECT_ID as SUI_CLOCK_OBJECT_ID5 } from "@mysten/sui.js/utils";
|
|
5492
|
+
import { SuiTxBlock as SuiKitTxBlock3 } from "@scallop-io/sui-kit";
|
|
5493
|
+
var requireObligationInfo2 = async (...params) => {
|
|
5494
|
+
const [builder, txBlock, obligationId, obligationKey] = params;
|
|
5495
|
+
if (params.length === 4 && obligationId && obligationKey && typeof obligationId === "string") {
|
|
5496
|
+
const obligationLocked = await getObligationLocked(
|
|
5497
|
+
builder.cache,
|
|
5498
|
+
obligationId
|
|
5499
|
+
);
|
|
5500
|
+
return { obligationId, obligationKey, obligationLocked };
|
|
5501
|
+
}
|
|
5502
|
+
const sender = requireSender(txBlock);
|
|
5503
|
+
const obligations = await getObligations(builder, sender);
|
|
5504
|
+
if (obligations.length === 0) {
|
|
5505
|
+
throw new Error(`No obligation found for sender ${sender}`);
|
|
5506
|
+
}
|
|
5507
|
+
const selectedObligation = obligations.find(
|
|
5508
|
+
(obligation) => obligation.id === obligationId || obligation.keyId === obligationKey
|
|
5509
|
+
) ?? obligations[0];
|
|
5510
|
+
return {
|
|
5511
|
+
obligationId: selectedObligation.id,
|
|
5512
|
+
obligationKey: selectedObligation.keyId,
|
|
5513
|
+
obligationLocked: selectedObligation.locked
|
|
5514
|
+
};
|
|
5515
|
+
};
|
|
5516
|
+
var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
|
|
5517
|
+
const borrowIncentiveIds = {
|
|
5518
|
+
borrowIncentivePkg: builder.address.get("borrowIncentive.id"),
|
|
5519
|
+
query: builder.address.get("borrowIncentive.query"),
|
|
5520
|
+
config: builder.address.get("borrowIncentive.config"),
|
|
5521
|
+
incentivePools: builder.address.get("borrowIncentive.incentivePools"),
|
|
5522
|
+
incentiveAccounts: builder.address.get(
|
|
5523
|
+
"borrowIncentive.incentiveAccounts"
|
|
5524
|
+
),
|
|
5525
|
+
obligationAccessStore: builder.address.get("core.obligationAccessStore")
|
|
5526
|
+
};
|
|
5527
|
+
const veScaIds = {
|
|
5528
|
+
table: builder.address.get("vesca.table"),
|
|
5529
|
+
treasury: builder.address.get("vesca.treasury"),
|
|
5530
|
+
config: builder.address.get("vesca.config")
|
|
5531
|
+
};
|
|
5532
|
+
return {
|
|
5533
|
+
stakeObligation: (obligationId, obligationKey) => {
|
|
5534
|
+
txBlock.moveCall(
|
|
5535
|
+
`${borrowIncentiveIds.borrowIncentivePkg}::user::stake`,
|
|
5536
|
+
[
|
|
5537
|
+
borrowIncentiveIds.config,
|
|
5538
|
+
borrowIncentiveIds.incentivePools,
|
|
5539
|
+
borrowIncentiveIds.incentiveAccounts,
|
|
5540
|
+
obligationKey,
|
|
5541
|
+
obligationId,
|
|
5542
|
+
borrowIncentiveIds.obligationAccessStore,
|
|
5543
|
+
SUI_CLOCK_OBJECT_ID5
|
|
5544
|
+
]
|
|
5545
|
+
);
|
|
5546
|
+
},
|
|
5547
|
+
stakeObligationWithVesca: (obligationId, obligationKey, veScaKey) => {
|
|
5548
|
+
txBlock.moveCall(
|
|
5549
|
+
`${borrowIncentiveIds.borrowIncentivePkg}::user::stake_with_ve_sca`,
|
|
5550
|
+
[
|
|
5551
|
+
borrowIncentiveIds.config,
|
|
5552
|
+
borrowIncentiveIds.incentivePools,
|
|
5553
|
+
borrowIncentiveIds.incentiveAccounts,
|
|
5554
|
+
obligationKey,
|
|
5555
|
+
obligationId,
|
|
5556
|
+
borrowIncentiveIds.obligationAccessStore,
|
|
5557
|
+
veScaIds.config,
|
|
5558
|
+
veScaIds.treasury,
|
|
5559
|
+
veScaIds.table,
|
|
5560
|
+
veScaKey,
|
|
5561
|
+
SUI_CLOCK_OBJECT_ID5
|
|
5562
|
+
],
|
|
5563
|
+
[]
|
|
5564
|
+
);
|
|
5565
|
+
},
|
|
5566
|
+
unstakeObligation: (obligationId, obligationKey) => {
|
|
5567
|
+
txBlock.moveCall(
|
|
5568
|
+
`${borrowIncentiveIds.borrowIncentivePkg}::user::unstake`,
|
|
5569
|
+
[
|
|
5570
|
+
borrowIncentiveIds.config,
|
|
5571
|
+
borrowIncentiveIds.incentivePools,
|
|
5572
|
+
borrowIncentiveIds.incentiveAccounts,
|
|
5573
|
+
obligationKey,
|
|
5574
|
+
obligationId,
|
|
5575
|
+
SUI_CLOCK_OBJECT_ID5
|
|
5576
|
+
]
|
|
5577
|
+
);
|
|
5578
|
+
},
|
|
5579
|
+
claimBorrowIncentive: (obligationId, obligationKey, coinName, rewardCoinName) => {
|
|
5580
|
+
const rewardCoinNames = builder.utils.getBorrowIncentiveRewardCoinName(coinName);
|
|
5581
|
+
if (rewardCoinNames.includes(rewardCoinName) === false) {
|
|
5582
|
+
throw new Error(`Invalid reward coin name ${rewardCoinName}`);
|
|
5583
|
+
}
|
|
5584
|
+
const rewardType = builder.utils.parseCoinType(rewardCoinName);
|
|
5585
|
+
return txBlock.moveCall(
|
|
5586
|
+
`${borrowIncentiveIds.borrowIncentivePkg}::user::redeem_rewards`,
|
|
5587
|
+
[
|
|
5588
|
+
borrowIncentiveIds.config,
|
|
5589
|
+
borrowIncentiveIds.incentivePools,
|
|
5590
|
+
borrowIncentiveIds.incentiveAccounts,
|
|
5591
|
+
obligationKey,
|
|
5592
|
+
obligationId,
|
|
5593
|
+
SUI_CLOCK_OBJECT_ID5
|
|
5594
|
+
],
|
|
5595
|
+
[rewardType]
|
|
5596
|
+
);
|
|
5597
|
+
},
|
|
5598
|
+
deactivateBoost: (obligation, veScaKey) => {
|
|
5599
|
+
return txBlock.moveCall(
|
|
5600
|
+
`${borrowIncentiveIds.borrowIncentivePkg}::user::deactivate_boost`,
|
|
5601
|
+
[
|
|
5602
|
+
borrowIncentiveIds.config,
|
|
5603
|
+
borrowIncentiveIds.incentivePools,
|
|
5604
|
+
borrowIncentiveIds.incentiveAccounts,
|
|
5605
|
+
obligation,
|
|
5606
|
+
veScaKey,
|
|
5607
|
+
SUI_CLOCK_OBJECT_ID5
|
|
5608
|
+
]
|
|
5609
|
+
);
|
|
5610
|
+
}
|
|
5611
|
+
};
|
|
5612
|
+
};
|
|
5613
|
+
var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
|
|
5614
|
+
return {
|
|
5615
|
+
stakeObligationQuick: async (obligation, obligationKey) => {
|
|
5616
|
+
const {
|
|
5617
|
+
obligationId: obligationArg,
|
|
5618
|
+
obligationKey: obligationKeyArg,
|
|
5619
|
+
obligationLocked
|
|
5620
|
+
} = await requireObligationInfo2(
|
|
5621
|
+
builder,
|
|
5622
|
+
txBlock,
|
|
5623
|
+
obligation,
|
|
5624
|
+
obligationKey
|
|
5625
|
+
);
|
|
5626
|
+
const unstakeObligationBeforeStake = !!txBlock.txBlock.blockData.transactions.find(
|
|
5627
|
+
(txn) => txn.kind === "MoveCall" && (txn.target === `${OLD_BORROW_INCENTIVE_PROTOCOL_ID}::user::unstake` || txn.target === `${builder.address.get("borrowIncentive.id")}::user::unstake`)
|
|
5628
|
+
);
|
|
5629
|
+
if (!obligationLocked || unstakeObligationBeforeStake) {
|
|
5630
|
+
txBlock.stakeObligation(obligationArg, obligationKeyArg);
|
|
5631
|
+
}
|
|
5632
|
+
},
|
|
5633
|
+
stakeObligationWithVeScaQuick: async (obligation, obligationKey, veScaKey) => {
|
|
5634
|
+
const {
|
|
5635
|
+
obligationId: obligationArg,
|
|
5636
|
+
obligationKey: obligationKeyArg,
|
|
5637
|
+
obligationLocked
|
|
5638
|
+
} = await requireObligationInfo2(
|
|
5639
|
+
builder,
|
|
5640
|
+
txBlock,
|
|
5641
|
+
obligation,
|
|
5642
|
+
obligationKey
|
|
5643
|
+
);
|
|
5644
|
+
const unstakeObligationBeforeStake = !!txBlock.txBlock.blockData.transactions.find(
|
|
5645
|
+
(txn) => txn.kind === "MoveCall" && (txn.target === `${OLD_BORROW_INCENTIVE_PROTOCOL_ID}::user::unstake` || txn.target === `${builder.address.get("borrowIncentive.id")}::user::unstake`)
|
|
5646
|
+
);
|
|
5647
|
+
if (!obligationLocked || unstakeObligationBeforeStake) {
|
|
5648
|
+
const bindedVeScaKey = await builder.query.getBindedVeScaKey(obligationArg);
|
|
5649
|
+
if (veScaKey && veScaKey !== bindedVeScaKey) {
|
|
5650
|
+
throw new Error(
|
|
5651
|
+
"Binded veScaKey is not equal to the provided veScaKey"
|
|
5652
|
+
);
|
|
5653
|
+
}
|
|
5654
|
+
if (bindedVeScaKey) {
|
|
5655
|
+
txBlock.stakeObligationWithVesca(
|
|
5656
|
+
obligationArg,
|
|
5657
|
+
obligationKeyArg,
|
|
5658
|
+
bindedVeScaKey
|
|
5659
|
+
);
|
|
5660
|
+
} else {
|
|
5661
|
+
txBlock.stakeObligation(obligationArg, obligationKeyArg);
|
|
5662
|
+
}
|
|
5663
|
+
}
|
|
5664
|
+
},
|
|
5665
|
+
unstakeObligationQuick: async (obligation, obligationKey) => {
|
|
5666
|
+
const {
|
|
5667
|
+
obligationId: obligationArg,
|
|
5668
|
+
obligationKey: obligationKeyArg,
|
|
5669
|
+
obligationLocked
|
|
5670
|
+
} = await requireObligationInfo2(
|
|
5671
|
+
builder,
|
|
5672
|
+
txBlock,
|
|
5673
|
+
obligation,
|
|
5674
|
+
obligationKey
|
|
5675
|
+
);
|
|
5676
|
+
if (obligationLocked) {
|
|
5677
|
+
txBlock.unstakeObligation(obligationArg, obligationKeyArg);
|
|
5678
|
+
}
|
|
5679
|
+
},
|
|
5680
|
+
claimBorrowIncentiveQuick: async (coinName, rewardCoinName, obligation, obligationKey) => {
|
|
5681
|
+
const { obligationId: obligationArg, obligationKey: obligationKeyArg } = await requireObligationInfo2(
|
|
5682
|
+
builder,
|
|
5683
|
+
txBlock,
|
|
5684
|
+
obligation,
|
|
5685
|
+
obligationKey
|
|
5686
|
+
);
|
|
5687
|
+
return txBlock.claimBorrowIncentive(
|
|
5688
|
+
obligationArg,
|
|
5689
|
+
obligationKeyArg,
|
|
5690
|
+
coinName,
|
|
5691
|
+
rewardCoinName
|
|
5692
|
+
);
|
|
5693
|
+
}
|
|
5694
|
+
};
|
|
5695
|
+
};
|
|
5696
|
+
var newBorrowIncentiveTxBlock = (builder, initTxBlock) => {
|
|
5697
|
+
const txBlock = initTxBlock instanceof TransactionBlock3 ? new SuiKitTxBlock3(initTxBlock) : initTxBlock ? initTxBlock : new SuiKitTxBlock3();
|
|
5698
|
+
const normalMethod = generateBorrowIncentiveNormalMethod({
|
|
5699
|
+
builder,
|
|
5700
|
+
txBlock
|
|
5701
|
+
});
|
|
5702
|
+
const normalTxBlock = new Proxy(txBlock, {
|
|
5703
|
+
get: (target, prop) => {
|
|
5704
|
+
if (prop in normalMethod) {
|
|
5705
|
+
return Reflect.get(normalMethod, prop);
|
|
5706
|
+
}
|
|
5707
|
+
return Reflect.get(target, prop);
|
|
5708
|
+
}
|
|
5709
|
+
});
|
|
5710
|
+
const quickMethod = generateBorrowIncentiveQuickMethod({
|
|
5711
|
+
builder,
|
|
5712
|
+
txBlock: normalTxBlock
|
|
5713
|
+
});
|
|
5714
|
+
return new Proxy(normalTxBlock, {
|
|
5715
|
+
get: (target, prop) => {
|
|
5716
|
+
if (prop in quickMethod) {
|
|
5717
|
+
return Reflect.get(quickMethod, prop);
|
|
5718
|
+
}
|
|
5719
|
+
return Reflect.get(target, prop);
|
|
5720
|
+
}
|
|
5721
|
+
});
|
|
5722
|
+
};
|
|
5482
5723
|
|
|
5483
5724
|
// src/builders/vescaBuilder.ts
|
|
5484
5725
|
import {
|
|
5485
|
-
SUI_CLOCK_OBJECT_ID as
|
|
5486
|
-
TransactionBlock as
|
|
5487
|
-
SuiTxBlock as
|
|
5726
|
+
SUI_CLOCK_OBJECT_ID as SUI_CLOCK_OBJECT_ID6,
|
|
5727
|
+
TransactionBlock as TransactionBlock4,
|
|
5728
|
+
SuiTxBlock as SuiKitTxBlock4
|
|
5488
5729
|
} from "@scallop-io/sui-kit";
|
|
5489
5730
|
var requireVeSca = async (...params) => {
|
|
5490
5731
|
const [builder, txBlock, veScaKey] = params;
|
|
@@ -5500,7 +5741,7 @@ var requireVeSca = async (...params) => {
|
|
|
5500
5741
|
if (veScas.length === 0) {
|
|
5501
5742
|
return void 0;
|
|
5502
5743
|
}
|
|
5503
|
-
return veScas[0];
|
|
5744
|
+
return veScaKey ? veScas.find(({ keyId }) => veScaKey === keyId) : veScas[0];
|
|
5504
5745
|
};
|
|
5505
5746
|
var generateNormalVeScaMethod = ({
|
|
5506
5747
|
builder,
|
|
@@ -5522,7 +5763,7 @@ var generateNormalVeScaMethod = ({
|
|
|
5522
5763
|
veScaIds.treasury,
|
|
5523
5764
|
scaCoin,
|
|
5524
5765
|
unlockAtInSecondTimestamp,
|
|
5525
|
-
|
|
5766
|
+
SUI_CLOCK_OBJECT_ID6
|
|
5526
5767
|
],
|
|
5527
5768
|
[]
|
|
5528
5769
|
);
|
|
@@ -5536,7 +5777,7 @@ var generateNormalVeScaMethod = ({
|
|
|
5536
5777
|
veScaIds.table,
|
|
5537
5778
|
veScaIds.treasury,
|
|
5538
5779
|
newUnlockAtInSecondTimestamp,
|
|
5539
|
-
|
|
5780
|
+
SUI_CLOCK_OBJECT_ID6
|
|
5540
5781
|
],
|
|
5541
5782
|
[]
|
|
5542
5783
|
);
|
|
@@ -5550,7 +5791,7 @@ var generateNormalVeScaMethod = ({
|
|
|
5550
5791
|
veScaIds.table,
|
|
5551
5792
|
veScaIds.treasury,
|
|
5552
5793
|
scaCoin,
|
|
5553
|
-
|
|
5794
|
+
SUI_CLOCK_OBJECT_ID6
|
|
5554
5795
|
],
|
|
5555
5796
|
[]
|
|
5556
5797
|
);
|
|
@@ -5565,7 +5806,7 @@ var generateNormalVeScaMethod = ({
|
|
|
5565
5806
|
veScaIds.treasury,
|
|
5566
5807
|
scaCoin,
|
|
5567
5808
|
newUnlockAtInSecondTimestamp,
|
|
5568
|
-
|
|
5809
|
+
SUI_CLOCK_OBJECT_ID6
|
|
5569
5810
|
],
|
|
5570
5811
|
[]
|
|
5571
5812
|
);
|
|
@@ -5578,7 +5819,7 @@ var generateNormalVeScaMethod = ({
|
|
|
5578
5819
|
veScaKey,
|
|
5579
5820
|
veScaIds.table,
|
|
5580
5821
|
veScaIds.treasury,
|
|
5581
|
-
|
|
5822
|
+
SUI_CLOCK_OBJECT_ID6
|
|
5582
5823
|
],
|
|
5583
5824
|
[]
|
|
5584
5825
|
);
|
|
@@ -5733,7 +5974,7 @@ var generateQuickVeScaMethod = ({
|
|
|
5733
5974
|
};
|
|
5734
5975
|
};
|
|
5735
5976
|
var newVeScaTxBlock = (builder, initTxBlock) => {
|
|
5736
|
-
const txBlock = initTxBlock instanceof
|
|
5977
|
+
const txBlock = initTxBlock instanceof TransactionBlock4 ? new SuiKitTxBlock4(initTxBlock) : initTxBlock ? initTxBlock : new SuiKitTxBlock4();
|
|
5737
5978
|
const normalMethod = generateNormalVeScaMethod({
|
|
5738
5979
|
builder,
|
|
5739
5980
|
txBlock
|
|
@@ -5760,241 +6001,6 @@ var newVeScaTxBlock = (builder, initTxBlock) => {
|
|
|
5760
6001
|
});
|
|
5761
6002
|
};
|
|
5762
6003
|
|
|
5763
|
-
// src/builders/borrowIncentiveBuilder.ts
|
|
5764
|
-
var requireObligationInfo2 = async (...params) => {
|
|
5765
|
-
const [builder, txBlock, obligationId, obligationKey] = params;
|
|
5766
|
-
if (params.length === 4 && obligationId && obligationKey && typeof obligationId === "string") {
|
|
5767
|
-
const obligationLocked = await getObligationLocked(
|
|
5768
|
-
builder.cache,
|
|
5769
|
-
obligationId
|
|
5770
|
-
);
|
|
5771
|
-
return { obligationId, obligationKey, obligationLocked };
|
|
5772
|
-
}
|
|
5773
|
-
const sender = requireSender(txBlock);
|
|
5774
|
-
const obligations = await getObligations(builder, sender);
|
|
5775
|
-
if (obligations.length === 0) {
|
|
5776
|
-
throw new Error(`No obligation found for sender ${sender}`);
|
|
5777
|
-
}
|
|
5778
|
-
const selectedObligation = obligations.find(
|
|
5779
|
-
(obligation) => obligation.id === obligationId || obligation.keyId === obligationKey
|
|
5780
|
-
) ?? obligations[0];
|
|
5781
|
-
return {
|
|
5782
|
-
obligationId: selectedObligation.id,
|
|
5783
|
-
obligationKey: selectedObligation.keyId,
|
|
5784
|
-
obligationLocked: selectedObligation.locked
|
|
5785
|
-
};
|
|
5786
|
-
};
|
|
5787
|
-
var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
|
|
5788
|
-
const borrowIncentiveIds = {
|
|
5789
|
-
borrowIncentivePkg: builder.address.get("borrowIncentive.id"),
|
|
5790
|
-
query: builder.address.get("borrowIncentive.query"),
|
|
5791
|
-
config: builder.address.get("borrowIncentive.config"),
|
|
5792
|
-
incentivePools: builder.address.get("borrowIncentive.incentivePools"),
|
|
5793
|
-
incentiveAccounts: builder.address.get(
|
|
5794
|
-
"borrowIncentive.incentiveAccounts"
|
|
5795
|
-
),
|
|
5796
|
-
obligationAccessStore: builder.address.get("core.obligationAccessStore")
|
|
5797
|
-
};
|
|
5798
|
-
const veScaIds = {
|
|
5799
|
-
table: builder.address.get("vesca.table"),
|
|
5800
|
-
treasury: builder.address.get("vesca.treasury"),
|
|
5801
|
-
config: builder.address.get("vesca.config")
|
|
5802
|
-
};
|
|
5803
|
-
return {
|
|
5804
|
-
stakeObligation: (obligationId, obligationKey) => {
|
|
5805
|
-
txBlock.moveCall(
|
|
5806
|
-
`${borrowIncentiveIds.borrowIncentivePkg}::user::stake`,
|
|
5807
|
-
[
|
|
5808
|
-
borrowIncentiveIds.config,
|
|
5809
|
-
borrowIncentiveIds.incentivePools,
|
|
5810
|
-
borrowIncentiveIds.incentiveAccounts,
|
|
5811
|
-
obligationKey,
|
|
5812
|
-
obligationId,
|
|
5813
|
-
borrowIncentiveIds.obligationAccessStore,
|
|
5814
|
-
SUI_CLOCK_OBJECT_ID6
|
|
5815
|
-
]
|
|
5816
|
-
);
|
|
5817
|
-
},
|
|
5818
|
-
stakeObligationWithVesca: (obligationId, obligationKey, veScaKey) => {
|
|
5819
|
-
txBlock.moveCall(
|
|
5820
|
-
`${borrowIncentiveIds.borrowIncentivePkg}::user::stake_with_ve_sca`,
|
|
5821
|
-
[
|
|
5822
|
-
borrowIncentiveIds.config,
|
|
5823
|
-
borrowIncentiveIds.incentivePools,
|
|
5824
|
-
borrowIncentiveIds.incentiveAccounts,
|
|
5825
|
-
obligationKey,
|
|
5826
|
-
obligationId,
|
|
5827
|
-
borrowIncentiveIds.obligationAccessStore,
|
|
5828
|
-
veScaIds.config,
|
|
5829
|
-
veScaIds.treasury,
|
|
5830
|
-
veScaIds.table,
|
|
5831
|
-
veScaKey,
|
|
5832
|
-
SUI_CLOCK_OBJECT_ID6
|
|
5833
|
-
],
|
|
5834
|
-
[]
|
|
5835
|
-
);
|
|
5836
|
-
},
|
|
5837
|
-
unstakeObligation: (obligationId, obligationKey) => {
|
|
5838
|
-
txBlock.moveCall(
|
|
5839
|
-
`${borrowIncentiveIds.borrowIncentivePkg}::user::unstake`,
|
|
5840
|
-
[
|
|
5841
|
-
borrowIncentiveIds.config,
|
|
5842
|
-
borrowIncentiveIds.incentivePools,
|
|
5843
|
-
borrowIncentiveIds.incentiveAccounts,
|
|
5844
|
-
obligationKey,
|
|
5845
|
-
obligationId,
|
|
5846
|
-
SUI_CLOCK_OBJECT_ID6
|
|
5847
|
-
]
|
|
5848
|
-
);
|
|
5849
|
-
},
|
|
5850
|
-
claimBorrowIncentive: (obligationId, obligationKey, coinName, rewardCoinName) => {
|
|
5851
|
-
const rewardCoinNames = builder.utils.getBorrowIncentiveRewardCoinName(coinName);
|
|
5852
|
-
if (rewardCoinNames.includes(rewardCoinName) === false) {
|
|
5853
|
-
throw new Error(`Invalid reward coin name ${rewardCoinName}`);
|
|
5854
|
-
}
|
|
5855
|
-
const rewardType = builder.utils.parseCoinType(rewardCoinName);
|
|
5856
|
-
return txBlock.moveCall(
|
|
5857
|
-
`${borrowIncentiveIds.borrowIncentivePkg}::user::redeem_rewards`,
|
|
5858
|
-
[
|
|
5859
|
-
borrowIncentiveIds.config,
|
|
5860
|
-
borrowIncentiveIds.incentivePools,
|
|
5861
|
-
borrowIncentiveIds.incentiveAccounts,
|
|
5862
|
-
obligationKey,
|
|
5863
|
-
obligationId,
|
|
5864
|
-
SUI_CLOCK_OBJECT_ID6
|
|
5865
|
-
],
|
|
5866
|
-
[rewardType]
|
|
5867
|
-
);
|
|
5868
|
-
},
|
|
5869
|
-
deactivateBoost: (obligation, veScaKey) => {
|
|
5870
|
-
return txBlock.moveCall(
|
|
5871
|
-
`${borrowIncentiveIds.borrowIncentivePkg}::user::deactivate_boost`,
|
|
5872
|
-
[
|
|
5873
|
-
borrowIncentiveIds.config,
|
|
5874
|
-
borrowIncentiveIds.incentivePools,
|
|
5875
|
-
borrowIncentiveIds.incentiveAccounts,
|
|
5876
|
-
obligation,
|
|
5877
|
-
veScaKey,
|
|
5878
|
-
SUI_CLOCK_OBJECT_ID6
|
|
5879
|
-
]
|
|
5880
|
-
);
|
|
5881
|
-
}
|
|
5882
|
-
};
|
|
5883
|
-
};
|
|
5884
|
-
var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
|
|
5885
|
-
return {
|
|
5886
|
-
stakeObligationQuick: async (obligation, obligationKey) => {
|
|
5887
|
-
const {
|
|
5888
|
-
obligationId: obligationArg,
|
|
5889
|
-
obligationKey: obligationKeyArg,
|
|
5890
|
-
obligationLocked
|
|
5891
|
-
} = await requireObligationInfo2(
|
|
5892
|
-
builder,
|
|
5893
|
-
txBlock,
|
|
5894
|
-
obligation,
|
|
5895
|
-
obligationKey
|
|
5896
|
-
);
|
|
5897
|
-
const unstakeObligationBeforeStake = !!txBlock.txBlock.blockData.transactions.find(
|
|
5898
|
-
(txn) => txn.kind === "MoveCall" && (txn.target === `${OLD_BORROW_INCENTIVE_PROTOCOL_ID}::user::unstake` || txn.target === `${builder.address.get("borrowIncentive.id")}::user::unstake`)
|
|
5899
|
-
);
|
|
5900
|
-
if (!obligationLocked || unstakeObligationBeforeStake) {
|
|
5901
|
-
txBlock.stakeObligation(obligationArg, obligationKeyArg);
|
|
5902
|
-
}
|
|
5903
|
-
},
|
|
5904
|
-
stakeObligationWithVeScaQuick: async (obligation, obligationKey, veScaKey) => {
|
|
5905
|
-
const {
|
|
5906
|
-
obligationId: obligationArg,
|
|
5907
|
-
obligationKey: obligationKeyArg,
|
|
5908
|
-
obligationLocked
|
|
5909
|
-
} = await requireObligationInfo2(
|
|
5910
|
-
builder,
|
|
5911
|
-
txBlock,
|
|
5912
|
-
obligation,
|
|
5913
|
-
obligationKey
|
|
5914
|
-
);
|
|
5915
|
-
const unstakeObligationBeforeStake = !!txBlock.txBlock.blockData.transactions.find(
|
|
5916
|
-
(txn) => txn.kind === "MoveCall" && (txn.target === `${OLD_BORROW_INCENTIVE_PROTOCOL_ID}::user::unstake` || txn.target === `${builder.address.get("borrowIncentive.id")}::user::unstake`)
|
|
5917
|
-
);
|
|
5918
|
-
if (!obligationLocked || unstakeObligationBeforeStake) {
|
|
5919
|
-
const veSca = await requireVeSca(builder, txBlock, veScaKey);
|
|
5920
|
-
if (veSca) {
|
|
5921
|
-
const bindedObligationId = await getBindedObligationId(
|
|
5922
|
-
builder,
|
|
5923
|
-
veSca.keyId
|
|
5924
|
-
);
|
|
5925
|
-
if ((!bindedObligationId || bindedObligationId === obligationArg) && veSca.currentVeScaBalance > 0) {
|
|
5926
|
-
txBlock.stakeObligationWithVesca(
|
|
5927
|
-
obligationArg,
|
|
5928
|
-
obligationKeyArg,
|
|
5929
|
-
veSca.keyId
|
|
5930
|
-
);
|
|
5931
|
-
} else {
|
|
5932
|
-
txBlock.stakeObligation(obligationArg, obligationKeyArg);
|
|
5933
|
-
}
|
|
5934
|
-
} else {
|
|
5935
|
-
txBlock.stakeObligation(obligationArg, obligationKeyArg);
|
|
5936
|
-
}
|
|
5937
|
-
}
|
|
5938
|
-
},
|
|
5939
|
-
unstakeObligationQuick: async (obligation, obligationKey) => {
|
|
5940
|
-
const {
|
|
5941
|
-
obligationId: obligationArg,
|
|
5942
|
-
obligationKey: obligationKeyArg,
|
|
5943
|
-
obligationLocked
|
|
5944
|
-
} = await requireObligationInfo2(
|
|
5945
|
-
builder,
|
|
5946
|
-
txBlock,
|
|
5947
|
-
obligation,
|
|
5948
|
-
obligationKey
|
|
5949
|
-
);
|
|
5950
|
-
if (obligationLocked) {
|
|
5951
|
-
txBlock.unstakeObligation(obligationArg, obligationKeyArg);
|
|
5952
|
-
}
|
|
5953
|
-
},
|
|
5954
|
-
claimBorrowIncentiveQuick: async (coinName, rewardCoinName, obligation, obligationKey) => {
|
|
5955
|
-
const { obligationId: obligationArg, obligationKey: obligationKeyArg } = await requireObligationInfo2(
|
|
5956
|
-
builder,
|
|
5957
|
-
txBlock,
|
|
5958
|
-
obligation,
|
|
5959
|
-
obligationKey
|
|
5960
|
-
);
|
|
5961
|
-
return txBlock.claimBorrowIncentive(
|
|
5962
|
-
obligationArg,
|
|
5963
|
-
obligationKeyArg,
|
|
5964
|
-
coinName,
|
|
5965
|
-
rewardCoinName
|
|
5966
|
-
);
|
|
5967
|
-
}
|
|
5968
|
-
};
|
|
5969
|
-
};
|
|
5970
|
-
var newBorrowIncentiveTxBlock = (builder, initTxBlock) => {
|
|
5971
|
-
const txBlock = initTxBlock instanceof TransactionBlock4 ? new SuiKitTxBlock4(initTxBlock) : initTxBlock ? initTxBlock : new SuiKitTxBlock4();
|
|
5972
|
-
const normalMethod = generateBorrowIncentiveNormalMethod({
|
|
5973
|
-
builder,
|
|
5974
|
-
txBlock
|
|
5975
|
-
});
|
|
5976
|
-
const normalTxBlock = new Proxy(txBlock, {
|
|
5977
|
-
get: (target, prop) => {
|
|
5978
|
-
if (prop in normalMethod) {
|
|
5979
|
-
return Reflect.get(normalMethod, prop);
|
|
5980
|
-
}
|
|
5981
|
-
return Reflect.get(target, prop);
|
|
5982
|
-
}
|
|
5983
|
-
});
|
|
5984
|
-
const quickMethod = generateBorrowIncentiveQuickMethod({
|
|
5985
|
-
builder,
|
|
5986
|
-
txBlock: normalTxBlock
|
|
5987
|
-
});
|
|
5988
|
-
return new Proxy(normalTxBlock, {
|
|
5989
|
-
get: (target, prop) => {
|
|
5990
|
-
if (prop in quickMethod) {
|
|
5991
|
-
return Reflect.get(quickMethod, prop);
|
|
5992
|
-
}
|
|
5993
|
-
return Reflect.get(target, prop);
|
|
5994
|
-
}
|
|
5995
|
-
});
|
|
5996
|
-
};
|
|
5997
|
-
|
|
5998
6004
|
// src/builders/referralBuilder.ts
|
|
5999
6005
|
import {
|
|
6000
6006
|
SUI_CLOCK_OBJECT_ID as SUI_CLOCK_OBJECT_ID7,
|