@scallop-io/sui-scallop-sdk 1.3.5-alpha.1 → 1.3.5-alpha.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.
- package/dist/constants/enum.d.ts +0 -1
- package/dist/index.js +70 -77
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +70 -76
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopClient.d.ts +4 -4
- package/dist/models/scallopUtils.d.ts +1 -8
- package/dist/types/builder/borrowIncentive.d.ts +6 -6
- package/package.json +1 -1
- package/src/builders/borrowIncentiveBuilder.ts +2 -13
- package/src/constants/enum.ts +0 -13
- package/src/models/scallopClient.ts +27 -10
- package/src/models/scallopUtils.ts +4 -14
- package/src/queries/borrowIncentiveQuery.ts +0 -1
- package/src/queries/portfolioQuery.ts +64 -58
- package/src/types/builder/borrowIncentive.ts +10 -15
package/dist/index.mjs
CHANGED
|
@@ -267,18 +267,6 @@ var spoolRewardCoins = {
|
|
|
267
267
|
var suiBridgeCoins = {
|
|
268
268
|
sbeth: "sbeth"
|
|
269
269
|
};
|
|
270
|
-
var borrowIncentiveRewardCoins = {
|
|
271
|
-
usdc: ["ssui", "ssca"],
|
|
272
|
-
sui: ["ssui", "ssca"],
|
|
273
|
-
wusdc: ["ssui", "ssca"],
|
|
274
|
-
wusdt: ["ssui", "ssca"],
|
|
275
|
-
sca: ["ssui", "ssca"],
|
|
276
|
-
afsui: ["ssui"],
|
|
277
|
-
hasui: ["ssui"],
|
|
278
|
-
vsui: ["ssui"],
|
|
279
|
-
weth: ["ssui"],
|
|
280
|
-
sbeth: ["ssui"]
|
|
281
|
-
};
|
|
282
270
|
var coinIds = {
|
|
283
271
|
usdc: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7",
|
|
284
272
|
sui: "0x0000000000000000000000000000000000000000000000000000000000000002",
|
|
@@ -2501,7 +2489,6 @@ var getBorrowIncentivePools = async (query, borrowIncentiveCoinNames = [
|
|
|
2501
2489
|
const borrowIncentivePools = {};
|
|
2502
2490
|
marketPools = marketPools ?? await query.getMarketPools(void 0, false, { coinPrices });
|
|
2503
2491
|
coinPrices = coinPrices ?? await query.getAllCoinPrices({ marketPools });
|
|
2504
|
-
console.log({ coinPrices });
|
|
2505
2492
|
if (indexer) {
|
|
2506
2493
|
const borrowIncentivePoolsIndexer = await query.indexer.getBorrowIncentivePools();
|
|
2507
2494
|
const updateBorrowIncentivePool = (pool) => {
|
|
@@ -3709,8 +3696,8 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
3709
3696
|
const collateralAssetCoinNames = [
|
|
3710
3697
|
...SUPPORT_COLLATERALS
|
|
3711
3698
|
];
|
|
3712
|
-
|
|
3713
|
-
|
|
3699
|
+
market = market ?? await query.queryMarket(indexer);
|
|
3700
|
+
coinPrices = coinPrices ?? await query.getAllCoinPrices({ marketPools: market.pools });
|
|
3714
3701
|
coinAmounts = coinAmounts || await query.getCoinAmounts(collateralAssetCoinNames, ownerAddress);
|
|
3715
3702
|
const [obligationQuery, borrowIncentivePools, borrowIncentiveAccounts] = await Promise.all([
|
|
3716
3703
|
query.queryObligation(obligationId),
|
|
@@ -3851,44 +3838,47 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
3851
3838
|
const borrowIncentivePool = borrowIncentivePools[coinName];
|
|
3852
3839
|
if (borrowIncentivePool) {
|
|
3853
3840
|
const rewards = [];
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
|
|
3874
|
-
BigNumber5(
|
|
3875
|
-
|
|
3876
|
-
|
|
3877
|
-
|
|
3878
|
-
|
|
3879
|
-
|
|
3880
|
-
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
|
|
3886
|
-
|
|
3887
|
-
|
|
3888
|
-
|
|
3841
|
+
Object.entries(borrowIncentiveAccount.pointList).forEach(
|
|
3842
|
+
([key, accountPoint]) => {
|
|
3843
|
+
const poolPoint = borrowIncentivePool.points[key];
|
|
3844
|
+
if (accountPoint && poolPoint) {
|
|
3845
|
+
let availableClaimAmount = BigNumber5(0);
|
|
3846
|
+
let availableClaimCoin = BigNumber5(0);
|
|
3847
|
+
const accountBorrowedAmount = BigNumber5(
|
|
3848
|
+
accountPoint.weightedAmount
|
|
3849
|
+
);
|
|
3850
|
+
const baseIndexRate = 1e9;
|
|
3851
|
+
const increasedPointRate = poolPoint.currentPointIndex ? Math.max(
|
|
3852
|
+
BigNumber5(poolPoint.currentPointIndex - accountPoint.index).dividedBy(baseIndexRate).toNumber(),
|
|
3853
|
+
0
|
|
3854
|
+
) : 1;
|
|
3855
|
+
availableClaimAmount = availableClaimAmount.plus(
|
|
3856
|
+
accountBorrowedAmount.multipliedBy(increasedPointRate).plus(accountPoint.points)
|
|
3857
|
+
);
|
|
3858
|
+
availableClaimCoin = availableClaimAmount.shiftedBy(
|
|
3859
|
+
-1 * poolPoint.coinDecimal
|
|
3860
|
+
);
|
|
3861
|
+
const weightScale = BigNumber5(1e12);
|
|
3862
|
+
const boostValue = BigNumber5(accountPoint.weightedAmount).div(
|
|
3863
|
+
BigNumber5(borrowIncentiveAccount.debtAmount).multipliedBy(poolPoint.baseWeight).dividedBy(weightScale)
|
|
3864
|
+
).isFinite() ? BigNumber5(accountPoint.weightedAmount).div(
|
|
3865
|
+
BigNumber5(borrowIncentiveAccount.debtAmount).multipliedBy(poolPoint.baseWeight).dividedBy(weightScale)
|
|
3866
|
+
).toNumber() : 1;
|
|
3867
|
+
if (availableClaimAmount.isGreaterThanOrEqualTo(0)) {
|
|
3868
|
+
rewards.push({
|
|
3869
|
+
coinName: poolPoint.coinName,
|
|
3870
|
+
coinType: poolPoint.coinType,
|
|
3871
|
+
symbol: poolPoint.symbol,
|
|
3872
|
+
coinDecimal: poolPoint.coinDecimal,
|
|
3873
|
+
coinPrice: poolPoint.coinPrice,
|
|
3874
|
+
availableClaimAmount: availableClaimAmount.toNumber(),
|
|
3875
|
+
availableClaimCoin: availableClaimCoin.toNumber(),
|
|
3876
|
+
boostValue
|
|
3877
|
+
});
|
|
3878
|
+
}
|
|
3889
3879
|
}
|
|
3890
3880
|
}
|
|
3891
|
-
|
|
3881
|
+
);
|
|
3892
3882
|
if (Object.keys(borrowIncentivePool.points).some((coinName2) => {
|
|
3893
3883
|
const rewardApr = borrowIncentivePool.points[coinName2]?.rewardApr;
|
|
3894
3884
|
return rewardApr !== Infinity && typeof rewardApr == "number" && rewardApr > 0;
|
|
@@ -4754,15 +4744,6 @@ var ScallopUtils = class {
|
|
|
4754
4744
|
this.getSpoolRewardCoinName = (stakeMarketCoinName) => {
|
|
4755
4745
|
return spoolRewardCoins[stakeMarketCoinName];
|
|
4756
4746
|
};
|
|
4757
|
-
/**
|
|
4758
|
-
* Get reward type of borrow incentive pool.
|
|
4759
|
-
*
|
|
4760
|
-
* @param borrowIncentiveCoinName - Support borrow incentive coin.
|
|
4761
|
-
* @return Borrow incentive reward coin name.
|
|
4762
|
-
*/
|
|
4763
|
-
this.getBorrowIncentiveRewardCoinName = (borrowIncentiveCoinName) => {
|
|
4764
|
-
return borrowIncentiveRewardCoins[borrowIncentiveCoinName];
|
|
4765
|
-
};
|
|
4766
4747
|
this.params = {
|
|
4767
4748
|
pythEndpoints: params.pythEndpoints ?? PYTH_ENDPOINTS["mainnet"],
|
|
4768
4749
|
...params
|
|
@@ -4833,6 +4814,9 @@ var ScallopUtils = class {
|
|
|
4833
4814
|
* @return Coin type.
|
|
4834
4815
|
*/
|
|
4835
4816
|
parseCoinType(coinName) {
|
|
4817
|
+
if (sCoinIds[coinName]) {
|
|
4818
|
+
return sCoinIds[coinName];
|
|
4819
|
+
}
|
|
4836
4820
|
coinName = isMarketCoin(coinName) ? this.parseCoinName(coinName) : coinName;
|
|
4837
4821
|
const coinPackageId = this.address.get(`core.coins.${coinName}.id`) || coinIds[coinName] || void 0;
|
|
4838
4822
|
if (!coinPackageId) {
|
|
@@ -6081,11 +6065,7 @@ var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
|
|
|
6081
6065
|
]
|
|
6082
6066
|
);
|
|
6083
6067
|
},
|
|
6084
|
-
claimBorrowIncentive: (obligationId, obligationKey,
|
|
6085
|
-
const rewardCoinNames = builder.utils.getBorrowIncentiveRewardCoinName(coinName);
|
|
6086
|
-
if (rewardCoinNames.includes(rewardCoinName) === false) {
|
|
6087
|
-
throw new Error(`Invalid reward coin name ${rewardCoinName}`);
|
|
6088
|
-
}
|
|
6068
|
+
claimBorrowIncentive: (obligationId, obligationKey, rewardCoinName) => {
|
|
6089
6069
|
const rewardType = builder.utils.parseCoinType(rewardCoinName);
|
|
6090
6070
|
return txBlock.moveCall(
|
|
6091
6071
|
`${borrowIncentiveIds.borrowIncentivePkg}::user::redeem_rewards`,
|
|
@@ -6178,7 +6158,7 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
|
|
|
6178
6158
|
txBlock.unstakeObligation(obligationArg, obligationKeyArg);
|
|
6179
6159
|
}
|
|
6180
6160
|
},
|
|
6181
|
-
claimBorrowIncentiveQuick: async (
|
|
6161
|
+
claimBorrowIncentiveQuick: async (rewardCoinName, obligation, obligationKey) => {
|
|
6182
6162
|
const { obligationId: obligationArg, obligationKey: obligationKeyArg } = await requireObligationInfo2(
|
|
6183
6163
|
builder,
|
|
6184
6164
|
txBlock,
|
|
@@ -6188,7 +6168,6 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
|
|
|
6188
6168
|
return txBlock.claimBorrowIncentive(
|
|
6189
6169
|
obligationArg,
|
|
6190
6170
|
obligationKeyArg,
|
|
6191
|
-
coinName,
|
|
6192
6171
|
rewardCoinName
|
|
6193
6172
|
);
|
|
6194
6173
|
}
|
|
@@ -8233,30 +8212,46 @@ var ScallopClient = class {
|
|
|
8233
8212
|
}
|
|
8234
8213
|
}
|
|
8235
8214
|
/**
|
|
8236
|
-
*
|
|
8215
|
+
* Claim borrow incentive reward.
|
|
8237
8216
|
*
|
|
8238
|
-
* @param
|
|
8217
|
+
* @param poolName
|
|
8239
8218
|
* @param amount - The amount of coins would deposit.
|
|
8240
8219
|
* @param sign - Decide to directly sign the transaction or return the transaction block.
|
|
8241
8220
|
* @param accountId - The stake account object.
|
|
8242
8221
|
* @param walletAddress - The wallet address of the owner.
|
|
8243
8222
|
* @return Transaction block response or transaction block
|
|
8244
8223
|
*/
|
|
8245
|
-
async claimBorrowIncentive(
|
|
8224
|
+
async claimBorrowIncentive(obligationId, obligationKeyId, sign = true, walletAddress) {
|
|
8246
8225
|
const txBlock = this.builder.createTxBlock();
|
|
8247
8226
|
const sender = walletAddress ?? this.walletAddress;
|
|
8248
8227
|
txBlock.setSender(sender);
|
|
8249
|
-
const
|
|
8250
|
-
|
|
8228
|
+
const rewardCoinsCollection = {};
|
|
8229
|
+
const obligationAccount = await this.query.getObligationAccount(obligationId);
|
|
8230
|
+
const rewardCoinNames = Object.values(obligationAccount.borrowIncentives).flatMap(
|
|
8231
|
+
({ rewards }) => rewards.filter(({ availableClaimAmount }) => availableClaimAmount > 0)
|
|
8232
|
+
).flatMap(({ coinName }) => coinName);
|
|
8233
|
+
for (const rewardCoinName of rewardCoinNames) {
|
|
8251
8234
|
const rewardCoin = await txBlock.claimBorrowIncentiveQuick(
|
|
8252
|
-
coinName,
|
|
8253
8235
|
rewardCoinName,
|
|
8254
8236
|
obligationId,
|
|
8255
8237
|
obligationKeyId
|
|
8256
8238
|
);
|
|
8257
|
-
|
|
8239
|
+
if (!rewardCoinsCollection[rewardCoinName]) {
|
|
8240
|
+
rewardCoinsCollection[rewardCoinName] = [rewardCoin];
|
|
8241
|
+
} else {
|
|
8242
|
+
rewardCoinsCollection[rewardCoinName].push(rewardCoin);
|
|
8243
|
+
}
|
|
8258
8244
|
}
|
|
8259
|
-
txBlock.transferObjects(
|
|
8245
|
+
txBlock.transferObjects(
|
|
8246
|
+
Object.values(rewardCoinsCollection).map((rewardCoins) => {
|
|
8247
|
+
const mergeDest = rewardCoins[0];
|
|
8248
|
+
if (rewardCoins.length > 1) {
|
|
8249
|
+
txBlock.mergeCoins(mergeDest, rewardCoins.slice(1));
|
|
8250
|
+
}
|
|
8251
|
+
return mergeDest;
|
|
8252
|
+
}),
|
|
8253
|
+
sender
|
|
8254
|
+
);
|
|
8260
8255
|
if (sign) {
|
|
8261
8256
|
return await this.suiKit.signAndSendTxn(
|
|
8262
8257
|
txBlock
|
|
@@ -8565,7 +8560,6 @@ export {
|
|
|
8565
8560
|
UNLOCK_ROUND_DURATION,
|
|
8566
8561
|
USE_TEST_ADDRESS,
|
|
8567
8562
|
assetCoins,
|
|
8568
|
-
borrowIncentiveRewardCoins,
|
|
8569
8563
|
coinDecimals,
|
|
8570
8564
|
coinIds,
|
|
8571
8565
|
marketCoins,
|