@scallop-io/sui-scallop-sdk 0.44.2 → 0.44.4
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/builders/borrowIncentiveBuilder.d.ts +12 -0
- package/dist/constants/common.d.ts +3 -1
- package/dist/constants/enum.d.ts +3 -2
- package/dist/index.js +815 -228
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +776 -192
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopClient.d.ts +33 -2
- package/dist/models/scallopQuery.d.ts +31 -10
- package/dist/models/scallopUtils.d.ts +11 -4
- package/dist/queries/borrowIncentiveQuery.d.ts +24 -0
- package/dist/queries/coreQuery.d.ts +8 -0
- package/dist/queries/index.d.ts +1 -0
- package/dist/queries/spoolQuery.d.ts +13 -5
- package/dist/types/address.d.ts +8 -0
- package/dist/types/builder/borrowIncentive.d.ts +31 -0
- package/dist/types/builder/index.d.ts +3 -1
- package/dist/types/constant/common.d.ts +5 -3
- package/dist/types/constant/enum.d.ts +6 -3
- package/dist/types/query/borrowIncentive.d.ts +118 -0
- package/dist/types/query/core.d.ts +1 -0
- package/dist/types/query/index.d.ts +1 -0
- package/dist/types/query/portfolio.d.ts +13 -0
- package/dist/types/query/spool.d.ts +12 -13
- package/dist/utils/builder.d.ts +8 -0
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/query.d.ts +33 -10
- package/dist/utils/util.d.ts +13 -0
- package/package.json +1 -1
- package/src/builders/borrowIncentiveBuilder.ts +257 -0
- package/src/builders/coreBuilder.ts +1 -14
- package/src/builders/index.ts +9 -2
- package/src/builders/spoolBuilder.ts +3 -16
- package/src/constants/common.ts +4 -1
- package/src/constants/enum.ts +8 -2
- package/src/models/scallopAddress.ts +8 -0
- package/src/models/scallopClient.ts +104 -2
- package/src/models/scallopQuery.ts +48 -14
- package/src/models/scallopUtils.ts +21 -5
- package/src/queries/borrowIncentiveQuery.ts +167 -0
- package/src/queries/coreQuery.ts +58 -15
- package/src/queries/index.ts +1 -0
- package/src/queries/portfolioQuery.ts +59 -5
- package/src/queries/spoolQuery.ts +87 -71
- package/src/types/address.ts +8 -0
- package/src/types/builder/borrowIncentive.ts +67 -0
- package/src/types/builder/index.ts +5 -1
- package/src/types/builder/spool.ts +0 -1
- package/src/types/constant/common.ts +10 -3
- package/src/types/constant/enum.ts +9 -3
- package/src/types/query/borrowIncentive.ts +150 -0
- package/src/types/query/core.ts +1 -1
- package/src/types/query/index.ts +1 -0
- package/src/types/query/portfolio.ts +16 -0
- package/src/types/query/spool.ts +28 -18
- package/src/utils/builder.ts +15 -0
- package/src/utils/index.ts +1 -1
- package/src/utils/query.ts +279 -72
- package/src/utils/util.ts +36 -2
- package/dist/utils/oracle.d.ts +0 -14
- package/src/utils/oracle.ts +0 -36
package/dist/index.js
CHANGED
|
@@ -33,12 +33,14 @@ __export(src_exports, {
|
|
|
33
33
|
ADDRESSES_ID: () => ADDRESSES_ID,
|
|
34
34
|
API_BASE_URL: () => API_BASE_URL,
|
|
35
35
|
PROTOCOL_OBJECT_ID: () => PROTOCOL_OBJECT_ID,
|
|
36
|
+
SUPPORT_BORROW_INCENTIVE_POOLS: () => SUPPORT_BORROW_INCENTIVE_POOLS,
|
|
37
|
+
SUPPORT_BORROW_INCENTIVE_REWARDS: () => SUPPORT_BORROW_INCENTIVE_REWARDS,
|
|
36
38
|
SUPPORT_COLLATERALS: () => SUPPORT_COLLATERALS,
|
|
37
39
|
SUPPORT_ORACLES: () => SUPPORT_ORACLES,
|
|
38
40
|
SUPPORT_PACKAGES: () => SUPPORT_PACKAGES,
|
|
39
41
|
SUPPORT_POOLS: () => SUPPORT_POOLS,
|
|
40
|
-
SUPPORT_REWARD_POOLS: () => SUPPORT_REWARD_POOLS,
|
|
41
42
|
SUPPORT_SPOOLS: () => SUPPORT_SPOOLS,
|
|
43
|
+
SUPPORT_SPOOLS_REWARDS: () => SUPPORT_SPOOLS_REWARDS,
|
|
42
44
|
Scallop: () => Scallop,
|
|
43
45
|
ScallopAddress: () => ScallopAddress,
|
|
44
46
|
ScallopBuilder: () => ScallopBuilder,
|
|
@@ -46,10 +48,11 @@ __export(src_exports, {
|
|
|
46
48
|
ScallopQuery: () => ScallopQuery,
|
|
47
49
|
ScallopUtils: () => ScallopUtils,
|
|
48
50
|
assetCoins: () => assetCoins,
|
|
51
|
+
borrowIncentiveRewardCoins: () => borrowIncentiveRewardCoins,
|
|
49
52
|
coinDecimals: () => coinDecimals,
|
|
50
53
|
coinIds: () => coinIds,
|
|
51
54
|
marketCoins: () => marketCoins,
|
|
52
|
-
|
|
55
|
+
spoolRewardCoins: () => spoolRewardCoins,
|
|
53
56
|
stakeMarketCoins: () => stakeMarketCoins,
|
|
54
57
|
voloCoinIds: () => voloCoinIds,
|
|
55
58
|
wormholeCoinIds: () => wormholeCoinIds
|
|
@@ -87,7 +90,9 @@ var SUPPORT_COLLATERALS = [
|
|
|
87
90
|
"vsui"
|
|
88
91
|
];
|
|
89
92
|
var SUPPORT_SPOOLS = ["ssui", "susdc", "susdt"];
|
|
90
|
-
var
|
|
93
|
+
var SUPPORT_SPOOLS_REWARDS = ["sui"];
|
|
94
|
+
var SUPPORT_BORROW_INCENTIVE_POOLS = ["sui", "usdc"];
|
|
95
|
+
var SUPPORT_BORROW_INCENTIVE_REWARDS = ["sui"];
|
|
91
96
|
var SUPPORT_ORACLES = ["supra", "switchboard", "pyth"];
|
|
92
97
|
var SUPPORT_PACKAGES = [
|
|
93
98
|
"coinDecimalsRegistry",
|
|
@@ -160,11 +165,15 @@ var stakeMarketCoins = {
|
|
|
160
165
|
susdc: "susdc",
|
|
161
166
|
susdt: "susdt"
|
|
162
167
|
};
|
|
163
|
-
var
|
|
168
|
+
var spoolRewardCoins = {
|
|
164
169
|
ssui: "sui",
|
|
165
170
|
susdc: "sui",
|
|
166
171
|
susdt: "sui"
|
|
167
172
|
};
|
|
173
|
+
var borrowIncentiveRewardCoins = {
|
|
174
|
+
sui: "sui",
|
|
175
|
+
usdc: "sui"
|
|
176
|
+
};
|
|
168
177
|
var coinIds = {
|
|
169
178
|
sui: "0x0000000000000000000000000000000000000000000000000000000000000002",
|
|
170
179
|
eth: "0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5",
|
|
@@ -191,7 +200,7 @@ var voloCoinIds = {
|
|
|
191
200
|
};
|
|
192
201
|
|
|
193
202
|
// src/models/scallop.ts
|
|
194
|
-
var
|
|
203
|
+
var import_sui_kit10 = require("@scallop-io/sui-kit");
|
|
195
204
|
|
|
196
205
|
// src/models/scallopAddress.ts
|
|
197
206
|
var import_axios = __toESM(require("axios"));
|
|
@@ -202,6 +211,7 @@ var EMPTY_ADDRESSES = {
|
|
|
202
211
|
market: "",
|
|
203
212
|
adminCap: "",
|
|
204
213
|
coinDecimalsRegistry: "",
|
|
214
|
+
obligationAccessStore: "",
|
|
205
215
|
coins: {
|
|
206
216
|
btc: {
|
|
207
217
|
id: "",
|
|
@@ -385,6 +395,13 @@ var EMPTY_ADDRESSES = {
|
|
|
385
395
|
rewardPoolId: ""
|
|
386
396
|
}
|
|
387
397
|
}
|
|
398
|
+
},
|
|
399
|
+
borrowIncentive: {
|
|
400
|
+
id: "",
|
|
401
|
+
adminCap: "",
|
|
402
|
+
query: "",
|
|
403
|
+
incentivePools: "",
|
|
404
|
+
incentiveAccounts: ""
|
|
388
405
|
}
|
|
389
406
|
};
|
|
390
407
|
var ScallopAddress = class {
|
|
@@ -688,46 +705,37 @@ var ScallopAddress = class {
|
|
|
688
705
|
};
|
|
689
706
|
|
|
690
707
|
// src/models/scallopClient.ts
|
|
691
|
-
var
|
|
692
|
-
var
|
|
708
|
+
var import_utils19 = require("@mysten/sui.js/utils");
|
|
709
|
+
var import_sui_kit9 = require("@scallop-io/sui-kit");
|
|
693
710
|
|
|
694
711
|
// src/models/scallopUtils.ts
|
|
695
|
-
var
|
|
696
|
-
var
|
|
712
|
+
var import_utils9 = require("@mysten/sui.js/utils");
|
|
713
|
+
var import_sui_kit4 = require("@scallop-io/sui-kit");
|
|
697
714
|
var import_pyth_sui_js = require("@pythnetwork/pyth-sui-js");
|
|
698
715
|
|
|
699
716
|
// src/models/scallopQuery.ts
|
|
700
|
-
var
|
|
717
|
+
var import_sui_kit3 = require("@scallop-io/sui-kit");
|
|
701
718
|
|
|
702
719
|
// src/queries/coreQuery.ts
|
|
720
|
+
var import_utils2 = require("@mysten/sui.js/utils");
|
|
703
721
|
var import_sui_kit = require("@scallop-io/sui-kit");
|
|
704
722
|
var import_bignumber2 = __toESM(require("bignumber.js"));
|
|
705
723
|
|
|
706
|
-
// src/utils/
|
|
707
|
-
var
|
|
708
|
-
const
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
const assetCoinName = assetCoinNames.find((assetCoinName2) => {
|
|
712
|
-
return address.get(`core.coins.${assetCoinName2}.oracle.pyth.feed`) === feed.id;
|
|
713
|
-
});
|
|
714
|
-
if (assetCoinName) {
|
|
715
|
-
const price = feed.price.price * 10 ** feed.price.expo;
|
|
716
|
-
return {
|
|
717
|
-
coinName: assetCoinName,
|
|
718
|
-
price,
|
|
719
|
-
publishTime: Number(feed.price.publishTime) * 10 ** 3
|
|
720
|
-
};
|
|
721
|
-
} else {
|
|
722
|
-
throw new Error("Invalid feed id");
|
|
724
|
+
// src/utils/builder.ts
|
|
725
|
+
var requireSender = (txBlock) => {
|
|
726
|
+
const sender = txBlock.blockData.sender;
|
|
727
|
+
if (!sender) {
|
|
728
|
+
throw new Error("Sender is required");
|
|
723
729
|
}
|
|
730
|
+
return sender;
|
|
724
731
|
};
|
|
725
732
|
|
|
726
733
|
// src/utils/query.ts
|
|
727
734
|
var import_bignumber = __toESM(require("bignumber.js"));
|
|
735
|
+
var import_utils = require("@mysten/sui.js/utils");
|
|
728
736
|
var parseOriginMarketPoolData = (originMarketPoolData) => {
|
|
729
737
|
return {
|
|
730
|
-
coinType:
|
|
738
|
+
coinType: (0, import_utils.normalizeStructTag)(originMarketPoolData.type.name),
|
|
731
739
|
// Parse origin data required for basic calculations.
|
|
732
740
|
maxBorrowRate: Number(originMarketPoolData.maxBorrowRate.value) / 2 ** 32,
|
|
733
741
|
borrowRate: Number(originMarketPoolData.interestRate.value) / 2 ** 32,
|
|
@@ -821,7 +829,7 @@ var calculateMarketPoolData = (utils, parsedMarketPoolData) => {
|
|
|
821
829
|
};
|
|
822
830
|
var parseOriginMarketCollateralData = (originMarketCollateralData) => {
|
|
823
831
|
return {
|
|
824
|
-
coinType:
|
|
832
|
+
coinType: (0, import_utils.normalizeStructTag)(originMarketCollateralData.type.name),
|
|
825
833
|
collateralFactor: Number(originMarketCollateralData.collateralFactor.value) / 2 ** 32,
|
|
826
834
|
liquidationFactor: Number(originMarketCollateralData.liquidationFactor.value) / 2 ** 32,
|
|
827
835
|
liquidationDiscount: Number(originMarketCollateralData.liquidationDiscount.value) / 2 ** 32,
|
|
@@ -851,48 +859,48 @@ var calculateMarketCollateralData = (utils, parsedMarketCollateralData) => {
|
|
|
851
859
|
depositCoin: depositCoin.toNumber()
|
|
852
860
|
};
|
|
853
861
|
};
|
|
854
|
-
var
|
|
862
|
+
var parseOriginSpoolData = (originSpoolData) => {
|
|
855
863
|
return {
|
|
856
|
-
stakeType:
|
|
857
|
-
maxPoint: Number(
|
|
858
|
-
distributedPoint: Number(
|
|
859
|
-
pointPerPeriod: Number(
|
|
860
|
-
period: Number(
|
|
861
|
-
maxStake: Number(
|
|
862
|
-
staked: Number(
|
|
863
|
-
index: Number(
|
|
864
|
-
createdAt: Number(
|
|
865
|
-
lastUpdate: Number(
|
|
864
|
+
stakeType: (0, import_utils.normalizeStructTag)(originSpoolData.stakeType.fields.name),
|
|
865
|
+
maxPoint: Number(originSpoolData.maxDistributedPoint),
|
|
866
|
+
distributedPoint: Number(originSpoolData.distributedPoint),
|
|
867
|
+
pointPerPeriod: Number(originSpoolData.distributedPointPerPeriod),
|
|
868
|
+
period: Number(originSpoolData.pointDistributionTime),
|
|
869
|
+
maxStake: Number(originSpoolData.maxStake),
|
|
870
|
+
staked: Number(originSpoolData.stakes),
|
|
871
|
+
index: Number(originSpoolData.index),
|
|
872
|
+
createdAt: Number(originSpoolData.createdAt),
|
|
873
|
+
lastUpdate: Number(originSpoolData.lastUpdate)
|
|
866
874
|
};
|
|
867
875
|
};
|
|
868
|
-
var
|
|
876
|
+
var calculateSpoolData = (parsedSpoolData, stakeMarketCoinPrice, stakeMarketCoinDecimal) => {
|
|
869
877
|
const baseIndexRate = 1e9;
|
|
870
878
|
const distributedPointPerSec = (0, import_bignumber.default)(
|
|
871
|
-
|
|
872
|
-
).dividedBy(
|
|
873
|
-
const pointPerSec = (0, import_bignumber.default)(
|
|
874
|
-
|
|
879
|
+
parsedSpoolData.pointPerPeriod
|
|
880
|
+
).dividedBy(parsedSpoolData.period);
|
|
881
|
+
const pointPerSec = (0, import_bignumber.default)(parsedSpoolData.pointPerPeriod).dividedBy(
|
|
882
|
+
parsedSpoolData.period
|
|
875
883
|
);
|
|
876
|
-
const remainingPeriod = (0, import_bignumber.default)(
|
|
877
|
-
const startDate =
|
|
878
|
-
const endDate = remainingPeriod.plus(
|
|
884
|
+
const remainingPeriod = (0, import_bignumber.default)(parsedSpoolData.maxPoint).minus(parsedSpoolData.distributedPoint).dividedBy(pointPerSec);
|
|
885
|
+
const startDate = parsedSpoolData.createdAt;
|
|
886
|
+
const endDate = remainingPeriod.plus(parsedSpoolData.lastUpdate).integerValue().toNumber();
|
|
879
887
|
const timeDelta = (0, import_bignumber.default)(
|
|
880
|
-
Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) -
|
|
881
|
-
).dividedBy(
|
|
882
|
-
const remainingPoints = (0, import_bignumber.default)(
|
|
883
|
-
|
|
888
|
+
Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) - parsedSpoolData.lastUpdate
|
|
889
|
+
).dividedBy(parsedSpoolData.period).toFixed(0);
|
|
890
|
+
const remainingPoints = (0, import_bignumber.default)(parsedSpoolData.maxPoint).minus(
|
|
891
|
+
parsedSpoolData.distributedPoint
|
|
884
892
|
);
|
|
885
893
|
const accumulatedPoints = import_bignumber.default.minimum(
|
|
886
|
-
(0, import_bignumber.default)(timeDelta).multipliedBy(
|
|
894
|
+
(0, import_bignumber.default)(timeDelta).multipliedBy(parsedSpoolData.pointPerPeriod),
|
|
887
895
|
remainingPoints
|
|
888
896
|
);
|
|
889
|
-
const currentPointIndex = (0, import_bignumber.default)(
|
|
890
|
-
accumulatedPoints.dividedBy(
|
|
897
|
+
const currentPointIndex = (0, import_bignumber.default)(parsedSpoolData.index).plus(
|
|
898
|
+
accumulatedPoints.dividedBy(parsedSpoolData.staked).isFinite() ? (0, import_bignumber.default)(baseIndexRate).multipliedBy(accumulatedPoints).dividedBy(parsedSpoolData.staked) : 0
|
|
891
899
|
);
|
|
892
900
|
const currentTotalDistributedPoint = (0, import_bignumber.default)(
|
|
893
|
-
|
|
901
|
+
parsedSpoolData.distributedPoint
|
|
894
902
|
).plus(accumulatedPoints);
|
|
895
|
-
const stakedAmount = (0, import_bignumber.default)(
|
|
903
|
+
const stakedAmount = (0, import_bignumber.default)(parsedSpoolData.staked);
|
|
896
904
|
const stakedCoin = stakedAmount.shiftedBy(-1 * stakeMarketCoinDecimal);
|
|
897
905
|
const stakedValue = stakedCoin.multipliedBy(stakeMarketCoinPrice);
|
|
898
906
|
return {
|
|
@@ -907,35 +915,154 @@ var calculateStakePoolData = (parsedStakePoolData, stakeMarketCoinPrice, stakeMa
|
|
|
907
915
|
stakedValue: stakedValue.toNumber()
|
|
908
916
|
};
|
|
909
917
|
};
|
|
910
|
-
var
|
|
918
|
+
var parseOriginSpoolRewardPoolData = (originSpoolRewardPoolData) => {
|
|
919
|
+
return {
|
|
920
|
+
claimedRewards: Number(originSpoolRewardPoolData.claimed_rewards),
|
|
921
|
+
exchangeRateNumerator: Number(
|
|
922
|
+
originSpoolRewardPoolData.exchange_rate_numerator
|
|
923
|
+
),
|
|
924
|
+
exchangeRateDenominator: Number(
|
|
925
|
+
originSpoolRewardPoolData.exchange_rate_denominator
|
|
926
|
+
),
|
|
927
|
+
rewards: Number(originSpoolRewardPoolData.rewards),
|
|
928
|
+
spoolId: String(originSpoolRewardPoolData.spool_id)
|
|
929
|
+
};
|
|
930
|
+
};
|
|
931
|
+
var calculateSpoolRewardPoolData = (parsedSpoolData, parsedSpoolRewardPoolData, calculatedSpoolData, rewardCoinPrice, rewardCoinDecimal) => {
|
|
932
|
+
const rateYearFactor = 365 * 24 * 60 * 60;
|
|
933
|
+
const rewardPerSec = (0, import_bignumber.default)(calculatedSpoolData.distributedPointPerSec).multipliedBy(parsedSpoolRewardPoolData.exchangeRateNumerator).dividedBy(parsedSpoolRewardPoolData.exchangeRateDenominator);
|
|
934
|
+
const totalRewardAmount = (0, import_bignumber.default)(parsedSpoolData.maxPoint).multipliedBy(parsedSpoolRewardPoolData.exchangeRateNumerator).dividedBy(parsedSpoolRewardPoolData.exchangeRateDenominator);
|
|
935
|
+
const totalRewardCoin = totalRewardAmount.shiftedBy(-1 * rewardCoinDecimal);
|
|
936
|
+
const totalRewardValue = totalRewardCoin.multipliedBy(rewardCoinPrice);
|
|
937
|
+
const remaindRewardAmount = (0, import_bignumber.default)(parsedSpoolRewardPoolData.rewards);
|
|
938
|
+
const remaindRewardCoin = remaindRewardAmount.shiftedBy(
|
|
939
|
+
-1 * rewardCoinDecimal
|
|
940
|
+
);
|
|
941
|
+
const remaindRewardValue = remaindRewardCoin.multipliedBy(rewardCoinPrice);
|
|
942
|
+
const claimedRewardAmount = (0, import_bignumber.default)(
|
|
943
|
+
parsedSpoolRewardPoolData.claimedRewards
|
|
944
|
+
);
|
|
945
|
+
const claimedRewardCoin = claimedRewardAmount.shiftedBy(
|
|
946
|
+
-1 * rewardCoinDecimal
|
|
947
|
+
);
|
|
948
|
+
const claimedRewardValue = claimedRewardCoin.multipliedBy(rewardCoinPrice);
|
|
949
|
+
const rewardValueForYear = (0, import_bignumber.default)(rewardPerSec).shiftedBy(-1 * rewardCoinDecimal).multipliedBy(rateYearFactor).multipliedBy(rewardCoinPrice);
|
|
950
|
+
const rewardRate = rewardValueForYear.dividedBy(calculatedSpoolData.stakedValue).isFinite() ? rewardValueForYear.dividedBy(calculatedSpoolData.stakedValue).toNumber() : Infinity;
|
|
951
|
+
return {
|
|
952
|
+
rewardApr: rewardRate,
|
|
953
|
+
totalRewardAmount: totalRewardAmount.toNumber(),
|
|
954
|
+
totalRewardCoin: totalRewardCoin.toNumber(),
|
|
955
|
+
totalRewardValue: totalRewardValue.toNumber(),
|
|
956
|
+
remaindRewardAmount: remaindRewardAmount.toNumber(),
|
|
957
|
+
remaindRewardCoin: remaindRewardCoin.toNumber(),
|
|
958
|
+
remaindRewardValue: remaindRewardValue.toNumber(),
|
|
959
|
+
claimedRewardAmount: claimedRewardAmount.toNumber(),
|
|
960
|
+
claimedRewardCoin: claimedRewardCoin.toNumber(),
|
|
961
|
+
claimedRewardValue: claimedRewardValue.toNumber(),
|
|
962
|
+
rewardPerSec: rewardPerSec.toNumber()
|
|
963
|
+
};
|
|
964
|
+
};
|
|
965
|
+
var parseOriginBorrowIncentivePoolData = (originBorrowIncentivePoolData) => {
|
|
966
|
+
return {
|
|
967
|
+
poolType: (0, import_utils.normalizeStructTag)(originBorrowIncentivePoolData.pool_type.name),
|
|
968
|
+
maxPoint: Number(originBorrowIncentivePoolData.max_distributed_point),
|
|
969
|
+
distributedPoint: Number(originBorrowIncentivePoolData.distributed_point),
|
|
970
|
+
pointPerPeriod: Number(
|
|
971
|
+
originBorrowIncentivePoolData.distributed_point_per_period
|
|
972
|
+
),
|
|
973
|
+
period: Number(originBorrowIncentivePoolData.point_distribution_time),
|
|
974
|
+
maxStake: Number(originBorrowIncentivePoolData.max_stakes),
|
|
975
|
+
staked: Number(originBorrowIncentivePoolData.stakes),
|
|
976
|
+
index: Number(originBorrowIncentivePoolData.index),
|
|
977
|
+
createdAt: Number(originBorrowIncentivePoolData.created_at),
|
|
978
|
+
lastUpdate: Number(originBorrowIncentivePoolData.last_update)
|
|
979
|
+
};
|
|
980
|
+
};
|
|
981
|
+
var calculateBorrowIncentivePoolData = (parsedBorrowIncentivePoolData, borrowIncentiveCoinPrice, borrowIncentiveCoinDecimal) => {
|
|
982
|
+
const baseIndexRate = 1e9;
|
|
983
|
+
const distributedPointPerSec = (0, import_bignumber.default)(
|
|
984
|
+
parsedBorrowIncentivePoolData.pointPerPeriod
|
|
985
|
+
).dividedBy(parsedBorrowIncentivePoolData.period);
|
|
986
|
+
const pointPerSec = (0, import_bignumber.default)(
|
|
987
|
+
parsedBorrowIncentivePoolData.pointPerPeriod
|
|
988
|
+
).dividedBy(parsedBorrowIncentivePoolData.period);
|
|
989
|
+
const remainingPeriod = (0, import_bignumber.default)(parsedBorrowIncentivePoolData.maxPoint).minus(parsedBorrowIncentivePoolData.distributedPoint).dividedBy(pointPerSec);
|
|
990
|
+
const startDate = parsedBorrowIncentivePoolData.createdAt;
|
|
991
|
+
const endDate = remainingPeriod.plus(parsedBorrowIncentivePoolData.lastUpdate).integerValue().toNumber();
|
|
992
|
+
const timeDelta = (0, import_bignumber.default)(
|
|
993
|
+
Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) - parsedBorrowIncentivePoolData.lastUpdate
|
|
994
|
+
).dividedBy(parsedBorrowIncentivePoolData.period).toFixed(0);
|
|
995
|
+
const remainingPoints = (0, import_bignumber.default)(
|
|
996
|
+
parsedBorrowIncentivePoolData.maxPoint
|
|
997
|
+
).minus(parsedBorrowIncentivePoolData.distributedPoint);
|
|
998
|
+
const accumulatedPoints = import_bignumber.default.minimum(
|
|
999
|
+
(0, import_bignumber.default)(timeDelta).multipliedBy(
|
|
1000
|
+
parsedBorrowIncentivePoolData.pointPerPeriod
|
|
1001
|
+
),
|
|
1002
|
+
remainingPoints
|
|
1003
|
+
);
|
|
1004
|
+
const currentPointIndex = (0, import_bignumber.default)(parsedBorrowIncentivePoolData.index).plus(
|
|
1005
|
+
accumulatedPoints.dividedBy(parsedBorrowIncentivePoolData.staked).isFinite() ? (0, import_bignumber.default)(baseIndexRate).multipliedBy(accumulatedPoints).dividedBy(parsedBorrowIncentivePoolData.staked) : 0
|
|
1006
|
+
);
|
|
1007
|
+
const currentTotalDistributedPoint = (0, import_bignumber.default)(
|
|
1008
|
+
parsedBorrowIncentivePoolData.distributedPoint
|
|
1009
|
+
).plus(accumulatedPoints);
|
|
1010
|
+
const stakedAmount = (0, import_bignumber.default)(parsedBorrowIncentivePoolData.staked);
|
|
1011
|
+
const stakedCoin = stakedAmount.shiftedBy(-1 * borrowIncentiveCoinDecimal);
|
|
1012
|
+
const stakedValue = stakedCoin.multipliedBy(borrowIncentiveCoinPrice);
|
|
1013
|
+
return {
|
|
1014
|
+
distributedPointPerSec: distributedPointPerSec.toNumber(),
|
|
1015
|
+
accumulatedPoints: accumulatedPoints.toNumber(),
|
|
1016
|
+
currentPointIndex: currentPointIndex.toNumber(),
|
|
1017
|
+
currentTotalDistributedPoint: currentTotalDistributedPoint.toNumber(),
|
|
1018
|
+
startDate: new Date(startDate * 1e3),
|
|
1019
|
+
endDate: new Date(endDate * 1e3),
|
|
1020
|
+
stakedAmount: stakedAmount.toNumber(),
|
|
1021
|
+
stakedCoin: stakedCoin.toNumber(),
|
|
1022
|
+
stakedValue: stakedValue.toNumber()
|
|
1023
|
+
};
|
|
1024
|
+
};
|
|
1025
|
+
var parseOriginBorrowIncentiveRewardPoolData = (originBorrowIncentiveRewardPoolData) => {
|
|
911
1026
|
return {
|
|
912
|
-
|
|
913
|
-
|
|
1027
|
+
rewardType: (0, import_utils.normalizeStructTag)(
|
|
1028
|
+
originBorrowIncentiveRewardPoolData.reward_type.name
|
|
1029
|
+
),
|
|
1030
|
+
claimedRewards: Number(originBorrowIncentiveRewardPoolData.claimed_rewards),
|
|
1031
|
+
exchangeRateNumerator: Number(
|
|
1032
|
+
originBorrowIncentiveRewardPoolData.exchange_rate_numerator
|
|
1033
|
+
),
|
|
914
1034
|
exchangeRateDenominator: Number(
|
|
915
|
-
|
|
1035
|
+
originBorrowIncentiveRewardPoolData.exchange_rate_denominator
|
|
916
1036
|
),
|
|
917
|
-
|
|
918
|
-
|
|
1037
|
+
remainingRewards: Number(
|
|
1038
|
+
originBorrowIncentiveRewardPoolData.remaining_reward
|
|
1039
|
+
)
|
|
919
1040
|
};
|
|
920
1041
|
};
|
|
921
|
-
var
|
|
1042
|
+
var calculateBorrowIncentiveRewardPoolData = (parsedBorrowIncentivePoolData, parsedBorrowIncentiveRewardPoolData, calculatedBorrowIncentivePoolData, rewardCoinPrice, rewardCoinDecimal) => {
|
|
922
1043
|
const rateYearFactor = 365 * 24 * 60 * 60;
|
|
923
|
-
const rewardPerSec = (0, import_bignumber.default)(
|
|
924
|
-
|
|
1044
|
+
const rewardPerSec = (0, import_bignumber.default)(
|
|
1045
|
+
calculatedBorrowIncentivePoolData.distributedPointPerSec
|
|
1046
|
+
).multipliedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateNumerator).dividedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateDenominator);
|
|
1047
|
+
const totalRewardAmount = (0, import_bignumber.default)(parsedBorrowIncentivePoolData.maxPoint).multipliedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateNumerator).dividedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateDenominator);
|
|
925
1048
|
const totalRewardCoin = totalRewardAmount.shiftedBy(-1 * rewardCoinDecimal);
|
|
926
1049
|
const totalRewardValue = totalRewardCoin.multipliedBy(rewardCoinPrice);
|
|
927
|
-
const remaindRewardAmount = (0, import_bignumber.default)(
|
|
1050
|
+
const remaindRewardAmount = (0, import_bignumber.default)(
|
|
1051
|
+
parsedBorrowIncentiveRewardPoolData.remainingRewards
|
|
1052
|
+
);
|
|
928
1053
|
const remaindRewardCoin = remaindRewardAmount.shiftedBy(
|
|
929
1054
|
-1 * rewardCoinDecimal
|
|
930
1055
|
);
|
|
931
1056
|
const remaindRewardValue = remaindRewardCoin.multipliedBy(rewardCoinPrice);
|
|
932
|
-
const claimedRewardAmount = (0, import_bignumber.default)(
|
|
1057
|
+
const claimedRewardAmount = (0, import_bignumber.default)(
|
|
1058
|
+
parsedBorrowIncentiveRewardPoolData.claimedRewards
|
|
1059
|
+
);
|
|
933
1060
|
const claimedRewardCoin = claimedRewardAmount.shiftedBy(
|
|
934
1061
|
-1 * rewardCoinDecimal
|
|
935
1062
|
);
|
|
936
1063
|
const claimedRewardValue = claimedRewardCoin.multipliedBy(rewardCoinPrice);
|
|
937
1064
|
const rewardValueForYear = (0, import_bignumber.default)(rewardPerSec).shiftedBy(-1 * rewardCoinDecimal).multipliedBy(rateYearFactor).multipliedBy(rewardCoinPrice);
|
|
938
|
-
const rewardRate = rewardValueForYear.dividedBy(
|
|
1065
|
+
const rewardRate = rewardValueForYear.dividedBy(calculatedBorrowIncentivePoolData.stakedValue).isFinite() ? rewardValueForYear.dividedBy(calculatedBorrowIncentivePoolData.stakedValue).toNumber() : Infinity;
|
|
939
1066
|
return {
|
|
940
1067
|
rewardApr: rewardRate,
|
|
941
1068
|
totalRewardAmount: totalRewardAmount.toNumber(),
|
|
@@ -947,9 +1074,18 @@ var calculateRewardPoolData = (parsedStakePoolData, parsedRewardPoolData, calcul
|
|
|
947
1074
|
claimedRewardAmount: claimedRewardAmount.toNumber(),
|
|
948
1075
|
claimedRewardCoin: claimedRewardCoin.toNumber(),
|
|
949
1076
|
claimedRewardValue: claimedRewardValue.toNumber(),
|
|
950
|
-
rewardPerSec: rewardPerSec.toNumber()
|
|
951
|
-
|
|
952
|
-
|
|
1077
|
+
rewardPerSec: rewardPerSec.toNumber()
|
|
1078
|
+
};
|
|
1079
|
+
};
|
|
1080
|
+
var parseOriginBorrowIncentiveAccountData = (originBorrowIncentiveAccountData) => {
|
|
1081
|
+
return {
|
|
1082
|
+
poolType: (0, import_utils.normalizeStructTag)(
|
|
1083
|
+
originBorrowIncentiveAccountData.pool_type.name
|
|
1084
|
+
),
|
|
1085
|
+
amount: Number(originBorrowIncentiveAccountData.amount),
|
|
1086
|
+
index: Number(originBorrowIncentiveAccountData.index),
|
|
1087
|
+
points: Number(originBorrowIncentiveAccountData.points),
|
|
1088
|
+
totalPoints: Number(originBorrowIncentiveAccountData.total_points)
|
|
953
1089
|
};
|
|
954
1090
|
};
|
|
955
1091
|
var minBigNumber = (...args) => {
|
|
@@ -967,7 +1103,7 @@ var isMarketCoin = (coinName) => {
|
|
|
967
1103
|
.../* @__PURE__ */ new Set([
|
|
968
1104
|
...SUPPORT_POOLS,
|
|
969
1105
|
...SUPPORT_COLLATERALS,
|
|
970
|
-
...
|
|
1106
|
+
...SUPPORT_SPOOLS_REWARDS
|
|
971
1107
|
])
|
|
972
1108
|
].includes(assetCoinName);
|
|
973
1109
|
};
|
|
@@ -983,6 +1119,24 @@ var parseAssetSymbol = (coinName) => {
|
|
|
983
1119
|
return coinName.toUpperCase();
|
|
984
1120
|
}
|
|
985
1121
|
};
|
|
1122
|
+
var parseDataFromPythPriceFeed = (feed, address) => {
|
|
1123
|
+
const assetCoinNames = [
|
|
1124
|
+
.../* @__PURE__ */ new Set([...SUPPORT_POOLS, ...SUPPORT_COLLATERALS])
|
|
1125
|
+
];
|
|
1126
|
+
const assetCoinName = assetCoinNames.find((assetCoinName2) => {
|
|
1127
|
+
return address.get(`core.coins.${assetCoinName2}.oracle.pyth.feed`) === feed.id;
|
|
1128
|
+
});
|
|
1129
|
+
if (assetCoinName) {
|
|
1130
|
+
const price = feed.price.price * 10 ** feed.price.expo;
|
|
1131
|
+
return {
|
|
1132
|
+
coinName: assetCoinName,
|
|
1133
|
+
price,
|
|
1134
|
+
publishTime: Number(feed.price.publishTime) * 10 ** 3
|
|
1135
|
+
};
|
|
1136
|
+
} else {
|
|
1137
|
+
throw new Error("Invalid feed id");
|
|
1138
|
+
}
|
|
1139
|
+
};
|
|
986
1140
|
|
|
987
1141
|
// src/queries/coreQuery.ts
|
|
988
1142
|
var queryMarket = async (query) => {
|
|
@@ -996,6 +1150,12 @@ var queryMarket = async (query) => {
|
|
|
996
1150
|
const pools = {};
|
|
997
1151
|
const collaterals = {};
|
|
998
1152
|
for (const pool of marketData.pools) {
|
|
1153
|
+
const coinType = (0, import_utils2.normalizeStructTag)(pool.type.name);
|
|
1154
|
+
const poolCoinName = query.utils.parseCoinNameFromType(coinType);
|
|
1155
|
+
const coinPrice = (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName] ?? 0;
|
|
1156
|
+
if (!SUPPORT_POOLS.includes(poolCoinName)) {
|
|
1157
|
+
continue;
|
|
1158
|
+
}
|
|
999
1159
|
const parsedMarketPoolData = parseOriginMarketPoolData({
|
|
1000
1160
|
type: pool.type,
|
|
1001
1161
|
maxBorrowRate: pool.maxBorrowRate,
|
|
@@ -1020,9 +1180,6 @@ var queryMarket = async (query) => {
|
|
|
1020
1180
|
query.utils,
|
|
1021
1181
|
parsedMarketPoolData
|
|
1022
1182
|
);
|
|
1023
|
-
const coinType = "0x" + pool.type.name;
|
|
1024
|
-
const poolCoinName = query.utils.parseCoinNameFromType(coinType);
|
|
1025
|
-
const coinPrice = (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName] ?? 0;
|
|
1026
1183
|
pools[poolCoinName] = {
|
|
1027
1184
|
coinName: poolCoinName,
|
|
1028
1185
|
symbol: query.utils.parseSymbol(poolCoinName),
|
|
@@ -1041,6 +1198,12 @@ var queryMarket = async (query) => {
|
|
|
1041
1198
|
};
|
|
1042
1199
|
}
|
|
1043
1200
|
for (const collateral of marketData.collaterals) {
|
|
1201
|
+
const coinType = (0, import_utils2.normalizeStructTag)(collateral.type.name);
|
|
1202
|
+
const collateralCoinName = query.utils.parseCoinNameFromType(coinType);
|
|
1203
|
+
const coinPrice = (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName] ?? 0;
|
|
1204
|
+
if (!SUPPORT_COLLATERALS.includes(collateralCoinName)) {
|
|
1205
|
+
continue;
|
|
1206
|
+
}
|
|
1044
1207
|
const parsedMarketCollateralData = parseOriginMarketCollateralData({
|
|
1045
1208
|
type: collateral.type,
|
|
1046
1209
|
collateralFactor: collateral.collateralFactor,
|
|
@@ -1055,9 +1218,6 @@ var queryMarket = async (query) => {
|
|
|
1055
1218
|
query.utils,
|
|
1056
1219
|
parsedMarketCollateralData
|
|
1057
1220
|
);
|
|
1058
|
-
const coinType = "0x" + collateral.type.name;
|
|
1059
|
-
const collateralCoinName = query.utils.parseCoinNameFromType(coinType);
|
|
1060
|
-
const coinPrice = (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName] ?? 0;
|
|
1061
1221
|
collaterals[collateralCoinName] = {
|
|
1062
1222
|
coinName: collateralCoinName,
|
|
1063
1223
|
symbol: query.utils.parseSymbol(collateralCoinName),
|
|
@@ -1344,11 +1504,27 @@ var getObligations = async (query, ownerAddress) => {
|
|
|
1344
1504
|
if (keyObject.content && "fields" in keyObject.content) {
|
|
1345
1505
|
const fields = keyObject.content.fields;
|
|
1346
1506
|
const obligationId = String(fields.ownership.fields.of);
|
|
1347
|
-
|
|
1507
|
+
const locked = await getObligationLocked(query, obligationId);
|
|
1508
|
+
obligations.push({ id: obligationId, keyId, locked });
|
|
1348
1509
|
}
|
|
1349
1510
|
}
|
|
1350
1511
|
return obligations;
|
|
1351
1512
|
};
|
|
1513
|
+
var getObligationLocked = async (query, obligationId) => {
|
|
1514
|
+
const obligationObjectResponse = await query.suiKit.client().getObject({
|
|
1515
|
+
id: obligationId,
|
|
1516
|
+
options: {
|
|
1517
|
+
showContent: true
|
|
1518
|
+
}
|
|
1519
|
+
});
|
|
1520
|
+
let obligationLocked = false;
|
|
1521
|
+
if (obligationObjectResponse.data && obligationObjectResponse?.data?.content?.dataType === "moveObject" && "lock_key" in obligationObjectResponse.data.content.fields) {
|
|
1522
|
+
obligationLocked = Boolean(
|
|
1523
|
+
obligationObjectResponse.data.content.fields.lock_key
|
|
1524
|
+
);
|
|
1525
|
+
}
|
|
1526
|
+
return obligationLocked;
|
|
1527
|
+
};
|
|
1352
1528
|
var queryObligation = async (query, obligationId) => {
|
|
1353
1529
|
const packageId = query.address.get("core.packages.query.id");
|
|
1354
1530
|
const queryTarget = `${packageId}::obligation_query::obligation_data`;
|
|
@@ -1523,7 +1699,7 @@ var getMarketCoinAmount = async (query, marketCoinName, ownerAddress) => {
|
|
|
1523
1699
|
};
|
|
1524
1700
|
|
|
1525
1701
|
// src/queries/spoolQuery.ts
|
|
1526
|
-
var
|
|
1702
|
+
var import_utils4 = require("@mysten/sui.js/utils");
|
|
1527
1703
|
var getSpools = async (query, stakeMarketCoinNames) => {
|
|
1528
1704
|
stakeMarketCoinNames = stakeMarketCoinNames || [...SUPPORT_SPOOLS];
|
|
1529
1705
|
const stakeCoinNames = stakeMarketCoinNames.map(
|
|
@@ -1544,31 +1720,31 @@ var getSpools = async (query, stakeMarketCoinNames) => {
|
|
|
1544
1720
|
}
|
|
1545
1721
|
return spools;
|
|
1546
1722
|
};
|
|
1547
|
-
var getSpool = async (query,
|
|
1548
|
-
const
|
|
1549
|
-
marketPool = marketPool || await query.getMarketPool(
|
|
1550
|
-
const poolId = query.address.get(`spool.pools.${
|
|
1723
|
+
var getSpool = async (query, marketCoinName, marketPool) => {
|
|
1724
|
+
const coinName = query.utils.parseCoinName(marketCoinName);
|
|
1725
|
+
marketPool = marketPool || await query.getMarketPool(coinName);
|
|
1726
|
+
const poolId = query.address.get(`spool.pools.${marketCoinName}.id`);
|
|
1551
1727
|
const rewardPoolId = query.address.get(
|
|
1552
|
-
`spool.pools.${
|
|
1728
|
+
`spool.pools.${marketCoinName}.rewardPoolId`
|
|
1553
1729
|
);
|
|
1554
1730
|
let spool = void 0;
|
|
1555
|
-
const
|
|
1731
|
+
const spoolObjectResponse = await query.suiKit.client().multiGetObjects({
|
|
1556
1732
|
ids: [poolId, rewardPoolId],
|
|
1557
1733
|
options: {
|
|
1558
1734
|
showContent: true
|
|
1559
1735
|
}
|
|
1560
1736
|
});
|
|
1561
|
-
if (marketPool &&
|
|
1562
|
-
const
|
|
1737
|
+
if (marketPool && spoolObjectResponse[0].data && spoolObjectResponse[1].data) {
|
|
1738
|
+
const rewardCoinName = query.utils.getSpoolRewardCoinName(marketCoinName);
|
|
1563
1739
|
const coinPrices = await query.utils.getCoinPrices([
|
|
1564
|
-
|
|
1565
|
-
|
|
1740
|
+
coinName,
|
|
1741
|
+
rewardCoinName
|
|
1566
1742
|
]);
|
|
1567
|
-
const
|
|
1568
|
-
const rewardPoolObject =
|
|
1569
|
-
if (
|
|
1570
|
-
const fields =
|
|
1571
|
-
const
|
|
1743
|
+
const spoolObject = spoolObjectResponse[0].data;
|
|
1744
|
+
const rewardPoolObject = spoolObjectResponse[1].data;
|
|
1745
|
+
if (spoolObject.content && "fields" in spoolObject.content) {
|
|
1746
|
+
const fields = spoolObject.content.fields;
|
|
1747
|
+
const parsedSpoolData = parseOriginSpoolData({
|
|
1572
1748
|
stakeType: fields.stake_type,
|
|
1573
1749
|
maxDistributedPoint: fields.max_distributed_point,
|
|
1574
1750
|
distributedPoint: fields.distributed_point,
|
|
@@ -1580,43 +1756,48 @@ var getSpool = async (query, stakeMarketCoinName, marketPool) => {
|
|
|
1580
1756
|
createdAt: fields.created_at,
|
|
1581
1757
|
lastUpdate: fields.last_update
|
|
1582
1758
|
});
|
|
1583
|
-
const
|
|
1584
|
-
const
|
|
1585
|
-
const
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1759
|
+
const marketCoinPrice = (coinPrices?.[coinName] ?? 0) * marketPool.conversionRate;
|
|
1760
|
+
const marketCoinDecimal = query.utils.getCoinDecimal(marketCoinName);
|
|
1761
|
+
const calculatedSpoolData = calculateSpoolData(
|
|
1762
|
+
parsedSpoolData,
|
|
1763
|
+
marketCoinPrice,
|
|
1764
|
+
marketCoinDecimal
|
|
1589
1765
|
);
|
|
1590
1766
|
if (rewardPoolObject.content && "fields" in rewardPoolObject.content) {
|
|
1591
1767
|
const fields2 = rewardPoolObject.content.fields;
|
|
1592
|
-
const
|
|
1768
|
+
const parsedSpoolRewardPoolData = parseOriginSpoolRewardPoolData({
|
|
1593
1769
|
claimed_rewards: fields2.claimed_rewards,
|
|
1594
1770
|
exchange_rate_numerator: fields2.exchange_rate_numerator,
|
|
1595
1771
|
exchange_rate_denominator: fields2.exchange_rate_denominator,
|
|
1596
1772
|
rewards: fields2.rewards,
|
|
1597
1773
|
spool_id: fields2.spool_id
|
|
1598
1774
|
});
|
|
1599
|
-
const rewardCoinPrice = coinPrices?.[
|
|
1600
|
-
const rewardCoinDecimal = query.utils.getCoinDecimal(
|
|
1601
|
-
const calculatedRewardPoolData =
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1775
|
+
const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
|
|
1776
|
+
const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
1777
|
+
const calculatedRewardPoolData = calculateSpoolRewardPoolData(
|
|
1778
|
+
parsedSpoolData,
|
|
1779
|
+
parsedSpoolRewardPoolData,
|
|
1780
|
+
calculatedSpoolData,
|
|
1605
1781
|
rewardCoinPrice,
|
|
1606
1782
|
rewardCoinDecimal
|
|
1607
1783
|
);
|
|
1608
1784
|
spool = {
|
|
1609
|
-
marketCoinName
|
|
1610
|
-
symbol: query.utils.parseSymbol(
|
|
1611
|
-
coinType: query.utils.parseCoinType(
|
|
1612
|
-
marketCoinType: query.utils.parseMarketCoinType(
|
|
1613
|
-
rewardCoinType: isMarketCoin(
|
|
1614
|
-
coinDecimal: query.utils.getCoinDecimal(
|
|
1615
|
-
rewardCoinDecimal: query.utils.getCoinDecimal(
|
|
1616
|
-
coinPrice: coinPrices?.[
|
|
1617
|
-
marketCoinPrice
|
|
1785
|
+
marketCoinName,
|
|
1786
|
+
symbol: query.utils.parseSymbol(marketCoinName),
|
|
1787
|
+
coinType: query.utils.parseCoinType(coinName),
|
|
1788
|
+
marketCoinType: query.utils.parseMarketCoinType(coinName),
|
|
1789
|
+
rewardCoinType: isMarketCoin(rewardCoinName) ? query.utils.parseMarketCoinType(rewardCoinName) : query.utils.parseCoinType(rewardCoinName),
|
|
1790
|
+
coinDecimal: query.utils.getCoinDecimal(coinName),
|
|
1791
|
+
rewardCoinDecimal: query.utils.getCoinDecimal(rewardCoinName),
|
|
1792
|
+
coinPrice: coinPrices?.[coinName] ?? 0,
|
|
1793
|
+
marketCoinPrice,
|
|
1618
1794
|
rewardCoinPrice,
|
|
1619
|
-
|
|
1795
|
+
maxPoint: parsedSpoolData.maxPoint,
|
|
1796
|
+
distributedPoint: parsedSpoolData.distributedPoint,
|
|
1797
|
+
maxStake: parsedSpoolData.maxStake,
|
|
1798
|
+
...calculatedSpoolData,
|
|
1799
|
+
exchangeRateNumerator: parsedSpoolRewardPoolData.exchangeRateNumerator,
|
|
1800
|
+
exchangeRateDenominator: parsedSpoolRewardPoolData.exchangeRateDenominator,
|
|
1620
1801
|
...calculatedRewardPoolData
|
|
1621
1802
|
};
|
|
1622
1803
|
}
|
|
@@ -1674,34 +1855,34 @@ var getStakeAccounts = async (query, ownerAddress) => {
|
|
|
1674
1855
|
const index = Number(fields.index);
|
|
1675
1856
|
const points = Number(fields.points);
|
|
1676
1857
|
const totalPoints = Number(fields.total_points);
|
|
1677
|
-
if ((0,
|
|
1858
|
+
if ((0, import_utils4.normalizeStructTag)(type) === stakeMarketCoinTypes.ssui) {
|
|
1678
1859
|
stakeAccounts.ssui.push({
|
|
1679
1860
|
id,
|
|
1680
|
-
type,
|
|
1861
|
+
type: (0, import_utils4.normalizeStructTag)(type),
|
|
1681
1862
|
stakePoolId,
|
|
1682
|
-
stakeType,
|
|
1863
|
+
stakeType: (0, import_utils4.normalizeStructTag)(stakeType),
|
|
1683
1864
|
staked,
|
|
1684
1865
|
index,
|
|
1685
1866
|
points,
|
|
1686
1867
|
totalPoints
|
|
1687
1868
|
});
|
|
1688
|
-
} else if ((0,
|
|
1869
|
+
} else if ((0, import_utils4.normalizeStructTag)(type) === stakeMarketCoinTypes.susdc) {
|
|
1689
1870
|
stakeAccounts.susdc.push({
|
|
1690
1871
|
id,
|
|
1691
|
-
type,
|
|
1872
|
+
type: (0, import_utils4.normalizeStructTag)(type),
|
|
1692
1873
|
stakePoolId,
|
|
1693
|
-
stakeType,
|
|
1874
|
+
stakeType: (0, import_utils4.normalizeStructTag)(stakeType),
|
|
1694
1875
|
staked,
|
|
1695
1876
|
index,
|
|
1696
1877
|
points,
|
|
1697
1878
|
totalPoints
|
|
1698
1879
|
});
|
|
1699
|
-
} else if ((0,
|
|
1880
|
+
} else if ((0, import_utils4.normalizeStructTag)(type) === stakeMarketCoinTypes.susdt) {
|
|
1700
1881
|
stakeAccounts.susdt.push({
|
|
1701
1882
|
id,
|
|
1702
|
-
type,
|
|
1883
|
+
type: (0, import_utils4.normalizeStructTag)(type),
|
|
1703
1884
|
stakePoolId,
|
|
1704
|
-
stakeType,
|
|
1885
|
+
stakeType: (0, import_utils4.normalizeStructTag)(stakeType),
|
|
1705
1886
|
staked,
|
|
1706
1887
|
index,
|
|
1707
1888
|
points,
|
|
@@ -1740,13 +1921,13 @@ var getStakePool = async (query, marketCoinName) => {
|
|
|
1740
1921
|
const lastUpdate = Number(fields.last_update);
|
|
1741
1922
|
stakePool = {
|
|
1742
1923
|
id,
|
|
1743
|
-
type,
|
|
1924
|
+
type: (0, import_utils4.normalizeStructTag)(type),
|
|
1744
1925
|
maxPoint,
|
|
1745
1926
|
distributedPoint,
|
|
1746
1927
|
pointPerPeriod,
|
|
1747
1928
|
period,
|
|
1748
1929
|
maxStake,
|
|
1749
|
-
stakeType,
|
|
1930
|
+
stakeType: (0, import_utils4.normalizeStructTag)(stakeType),
|
|
1750
1931
|
totalStaked,
|
|
1751
1932
|
index,
|
|
1752
1933
|
createdAt,
|
|
@@ -1756,32 +1937,32 @@ var getStakePool = async (query, marketCoinName) => {
|
|
|
1756
1937
|
}
|
|
1757
1938
|
return stakePool;
|
|
1758
1939
|
};
|
|
1759
|
-
var
|
|
1940
|
+
var getStakeRewardPool = async (query, marketCoinName) => {
|
|
1760
1941
|
const poolId = query.address.get(
|
|
1761
1942
|
`spool.pools.${marketCoinName}.rewardPoolId`
|
|
1762
1943
|
);
|
|
1763
|
-
let
|
|
1764
|
-
const
|
|
1944
|
+
let stakeRewardPool = void 0;
|
|
1945
|
+
const stakeRewardPoolObjectResponse = await query.suiKit.client().getObject({
|
|
1765
1946
|
id: poolId,
|
|
1766
1947
|
options: {
|
|
1767
1948
|
showContent: true,
|
|
1768
1949
|
showType: true
|
|
1769
1950
|
}
|
|
1770
1951
|
});
|
|
1771
|
-
if (
|
|
1772
|
-
const
|
|
1773
|
-
const id =
|
|
1774
|
-
const type =
|
|
1775
|
-
if (
|
|
1776
|
-
const fields =
|
|
1952
|
+
if (stakeRewardPoolObjectResponse.data) {
|
|
1953
|
+
const stakeRewardPoolObject = stakeRewardPoolObjectResponse.data;
|
|
1954
|
+
const id = stakeRewardPoolObject.objectId;
|
|
1955
|
+
const type = stakeRewardPoolObject.type;
|
|
1956
|
+
if (stakeRewardPoolObject.content && "fields" in stakeRewardPoolObject.content) {
|
|
1957
|
+
const fields = stakeRewardPoolObject.content.fields;
|
|
1777
1958
|
const stakePoolId = String(fields.spool_id);
|
|
1778
1959
|
const ratioNumerator = Number(fields.exchange_rate_numerator);
|
|
1779
1960
|
const ratioDenominator = Number(fields.exchange_rate_denominator);
|
|
1780
1961
|
const rewards = Number(fields.rewards);
|
|
1781
1962
|
const claimedRewards = Number(fields.claimed_rewards);
|
|
1782
|
-
|
|
1963
|
+
stakeRewardPool = {
|
|
1783
1964
|
id,
|
|
1784
|
-
type,
|
|
1965
|
+
type: (0, import_utils4.normalizeStructTag)(type),
|
|
1785
1966
|
stakePoolId,
|
|
1786
1967
|
ratioNumerator,
|
|
1787
1968
|
ratioDenominator,
|
|
@@ -1790,7 +1971,107 @@ var getRewardPool = async (query, marketCoinName) => {
|
|
|
1790
1971
|
};
|
|
1791
1972
|
}
|
|
1792
1973
|
}
|
|
1793
|
-
return
|
|
1974
|
+
return stakeRewardPool;
|
|
1975
|
+
};
|
|
1976
|
+
|
|
1977
|
+
// src/queries/borrowIncentiveQuery.ts
|
|
1978
|
+
var import_utils6 = require("@mysten/sui.js/utils");
|
|
1979
|
+
var import_sui_kit2 = require("@scallop-io/sui-kit");
|
|
1980
|
+
var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames) => {
|
|
1981
|
+
borrowIncentiveCoinNames = borrowIncentiveCoinNames || [
|
|
1982
|
+
...SUPPORT_BORROW_INCENTIVE_POOLS
|
|
1983
|
+
];
|
|
1984
|
+
const queryPkgId = query.address.get("borrowIncentive.query");
|
|
1985
|
+
const incentivePoolsId = query.address.get("borrowIncentive.incentivePools");
|
|
1986
|
+
const txBlock = new import_sui_kit2.SuiTxBlock();
|
|
1987
|
+
const queryTarget = `${queryPkgId}::incentive_pools_query::incentive_pools_data`;
|
|
1988
|
+
txBlock.moveCall(queryTarget, [incentivePoolsId], ["0x2::sui::SUI"]);
|
|
1989
|
+
const queryResult = await query.suiKit.inspectTxn(txBlock);
|
|
1990
|
+
const borrowIncentivePoolsQueryData = queryResult.events[0].parsedJson;
|
|
1991
|
+
const parsedBorrowIncentiveRewardPoolData = parseOriginBorrowIncentiveRewardPoolData(
|
|
1992
|
+
borrowIncentivePoolsQueryData.reward_pool
|
|
1993
|
+
);
|
|
1994
|
+
const rewardCoinType = parsedBorrowIncentiveRewardPoolData.rewardType;
|
|
1995
|
+
const borrowIncentivePools = {};
|
|
1996
|
+
for (const pool of borrowIncentivePoolsQueryData.incentive_pools) {
|
|
1997
|
+
const coinType = (0, import_utils6.normalizeStructTag)(pool.pool_type.name);
|
|
1998
|
+
const coinName = query.utils.parseCoinNameFromType(coinType);
|
|
1999
|
+
const rewardCoinName = query.utils.parseCoinNameFromType(rewardCoinType);
|
|
2000
|
+
if (!borrowIncentiveCoinNames.includes(coinName)) {
|
|
2001
|
+
continue;
|
|
2002
|
+
}
|
|
2003
|
+
const coinPrices = await query.utils.getCoinPrices([
|
|
2004
|
+
coinName,
|
|
2005
|
+
rewardCoinName
|
|
2006
|
+
]);
|
|
2007
|
+
const parsedBorrowIncentivePoolData = parseOriginBorrowIncentivePoolData(pool);
|
|
2008
|
+
const coinPrice = coinPrices?.[coinName] ?? 0;
|
|
2009
|
+
const coinDecimal = query.utils.getCoinDecimal(coinName);
|
|
2010
|
+
const calculatedBorrowIncentivePoolData = calculateBorrowIncentivePoolData(
|
|
2011
|
+
parsedBorrowIncentivePoolData,
|
|
2012
|
+
coinPrice,
|
|
2013
|
+
coinDecimal
|
|
2014
|
+
);
|
|
2015
|
+
const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
|
|
2016
|
+
const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
2017
|
+
const calculatedBorrowIncentiveRewardPoolData = calculateBorrowIncentiveRewardPoolData(
|
|
2018
|
+
parsedBorrowIncentivePoolData,
|
|
2019
|
+
parsedBorrowIncentiveRewardPoolData,
|
|
2020
|
+
calculatedBorrowIncentivePoolData,
|
|
2021
|
+
rewardCoinPrice,
|
|
2022
|
+
rewardCoinDecimal
|
|
2023
|
+
);
|
|
2024
|
+
borrowIncentivePools[coinName] = {
|
|
2025
|
+
coinName,
|
|
2026
|
+
symbol: query.utils.parseSymbol(coinName),
|
|
2027
|
+
coinType,
|
|
2028
|
+
rewardCoinType,
|
|
2029
|
+
coinDecimal,
|
|
2030
|
+
rewardCoinDecimal,
|
|
2031
|
+
coinPrice,
|
|
2032
|
+
rewardCoinPrice,
|
|
2033
|
+
maxPoint: parsedBorrowIncentivePoolData.maxPoint,
|
|
2034
|
+
distributedPoint: parsedBorrowIncentivePoolData.distributedPoint,
|
|
2035
|
+
maxStake: parsedBorrowIncentivePoolData.maxStake,
|
|
2036
|
+
...calculatedBorrowIncentivePoolData,
|
|
2037
|
+
exchangeRateNumerator: parsedBorrowIncentiveRewardPoolData.exchangeRateNumerator,
|
|
2038
|
+
exchangeRateDenominator: parsedBorrowIncentiveRewardPoolData.exchangeRateDenominator,
|
|
2039
|
+
...calculatedBorrowIncentiveRewardPoolData
|
|
2040
|
+
};
|
|
2041
|
+
}
|
|
2042
|
+
return borrowIncentivePools;
|
|
2043
|
+
};
|
|
2044
|
+
var queryBorrowIncentiveAccounts = async (query, obligationId, borrowIncentiveCoinNames) => {
|
|
2045
|
+
borrowIncentiveCoinNames = borrowIncentiveCoinNames || [
|
|
2046
|
+
...SUPPORT_BORROW_INCENTIVE_POOLS
|
|
2047
|
+
];
|
|
2048
|
+
const queryPkgId = query.address.get("borrowIncentive.query");
|
|
2049
|
+
const incentiveAccountsId = query.address.get(
|
|
2050
|
+
"borrowIncentive.incentiveAccounts"
|
|
2051
|
+
);
|
|
2052
|
+
const queryTarget = `${queryPkgId}::incentive_account_query::incentive_account_data`;
|
|
2053
|
+
const txBlock = new import_sui_kit2.SuiTxBlock();
|
|
2054
|
+
txBlock.moveCall(queryTarget, [incentiveAccountsId, obligationId]);
|
|
2055
|
+
const queryResult = await query.suiKit.inspectTxn(txBlock);
|
|
2056
|
+
const borrowIncentiveAccountsQueryData = queryResult.events[0].parsedJson;
|
|
2057
|
+
const borrowIncentiveAccounts = Object.values(
|
|
2058
|
+
borrowIncentiveAccountsQueryData.incentive_states
|
|
2059
|
+
).reduce((accounts, accountData) => {
|
|
2060
|
+
const parsedBorrowIncentiveAccount = parseOriginBorrowIncentiveAccountData(accountData);
|
|
2061
|
+
const poolType = parsedBorrowIncentiveAccount.poolType;
|
|
2062
|
+
const coinName = query.utils.parseCoinNameFromType(poolType);
|
|
2063
|
+
if (borrowIncentiveCoinNames && borrowIncentiveCoinNames.includes(coinName)) {
|
|
2064
|
+
accounts[coinName] = {
|
|
2065
|
+
poolType,
|
|
2066
|
+
amount: parsedBorrowIncentiveAccount.amount,
|
|
2067
|
+
points: parsedBorrowIncentiveAccount.points,
|
|
2068
|
+
totalPoints: parsedBorrowIncentiveAccount.totalPoints,
|
|
2069
|
+
index: parsedBorrowIncentiveAccount.index
|
|
2070
|
+
};
|
|
2071
|
+
}
|
|
2072
|
+
return accounts;
|
|
2073
|
+
}, {});
|
|
2074
|
+
return borrowIncentiveAccounts;
|
|
1794
2075
|
};
|
|
1795
2076
|
|
|
1796
2077
|
// src/queries/priceQuery.ts
|
|
@@ -1911,15 +2192,19 @@ var getLending = async (query, poolCoinName, ownerAddress, marketPool, spool, st
|
|
|
1911
2192
|
availableUnstakeAmount = availableUnstakeAmount.plus(
|
|
1912
2193
|
accountStakedMarketCoinAmount
|
|
1913
2194
|
);
|
|
1914
|
-
availableUnstakeCoin = availableUnstakeAmount.shiftedBy(
|
|
2195
|
+
availableUnstakeCoin = availableUnstakeAmount.shiftedBy(
|
|
2196
|
+
-1 * spool.coinDecimal
|
|
2197
|
+
);
|
|
1915
2198
|
const baseIndexRate = 1e9;
|
|
1916
2199
|
const increasedPointRate = spool?.currentPointIndex ? (0, import_bignumber3.default)(spool.currentPointIndex - stakeAccount.index).dividedBy(
|
|
1917
2200
|
baseIndexRate
|
|
1918
2201
|
) : 1;
|
|
1919
2202
|
availableClaimAmount = availableClaimAmount.plus(
|
|
1920
|
-
|
|
2203
|
+
accountStakedMarketCoinAmount.multipliedBy(increasedPointRate).plus(stakeAccount.points).multipliedBy(spool.exchangeRateNumerator).dividedBy(spool.exchangeRateDenominator)
|
|
2204
|
+
);
|
|
2205
|
+
availableClaimCoin = availableClaimAmount.shiftedBy(
|
|
2206
|
+
-1 * spool.rewardCoinDecimal
|
|
1921
2207
|
);
|
|
1922
|
-
availableClaimCoin = availableClaimAmount.shiftedBy(-1 * coinDecimal);
|
|
1923
2208
|
}
|
|
1924
2209
|
}
|
|
1925
2210
|
const suppliedAmount = (0, import_bignumber3.default)(marketCoinAmount).multipliedBy(
|
|
@@ -2004,10 +2289,13 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
|
|
|
2004
2289
|
])
|
|
2005
2290
|
];
|
|
2006
2291
|
const obligationQuery = await query.queryObligation(obligationId);
|
|
2292
|
+
const borrowIncentivePools = await query.getBorrowIncentivePools();
|
|
2293
|
+
const borrowIncentiveAccounts = await query.getBorrowIncentiveAccounts(obligationId);
|
|
2007
2294
|
coinPrices = coinPrices || await query.utils.getCoinPrices(assetCoinNames);
|
|
2008
2295
|
coinAmounts = coinAmounts || await query.getCoinAmounts(assetCoinNames, ownerAddress);
|
|
2009
2296
|
const collaterals = {};
|
|
2010
2297
|
const debts = {};
|
|
2298
|
+
const borrowIncentives = {};
|
|
2011
2299
|
let totalDepositedPools = 0;
|
|
2012
2300
|
let totalDepositedValue = (0, import_bignumber3.default)(0);
|
|
2013
2301
|
let totalBorrowCapacityValue = (0, import_bignumber3.default)(0);
|
|
@@ -2109,6 +2397,41 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
|
|
|
2109
2397
|
};
|
|
2110
2398
|
}
|
|
2111
2399
|
}
|
|
2400
|
+
for (const [poolCoinName, borrowIncentiveAccount] of Object.entries(
|
|
2401
|
+
borrowIncentiveAccounts
|
|
2402
|
+
)) {
|
|
2403
|
+
const coinName = poolCoinName;
|
|
2404
|
+
const borrowIncentivePool = borrowIncentivePools[coinName];
|
|
2405
|
+
let availableClaimAmount = (0, import_bignumber3.default)(0);
|
|
2406
|
+
let availableClaimCoin = (0, import_bignumber3.default)(0);
|
|
2407
|
+
if (borrowIncentivePool) {
|
|
2408
|
+
const accountBorrowedAmount = (0, import_bignumber3.default)(borrowIncentiveAccount.amount);
|
|
2409
|
+
const baseIndexRate = 1e9;
|
|
2410
|
+
const increasedPointRate = borrowIncentivePool.currentPointIndex ? (0, import_bignumber3.default)(
|
|
2411
|
+
borrowIncentivePool.currentPointIndex - borrowIncentiveAccount.index
|
|
2412
|
+
).dividedBy(baseIndexRate) : 1;
|
|
2413
|
+
availableClaimAmount = availableClaimAmount.plus(
|
|
2414
|
+
accountBorrowedAmount.multipliedBy(increasedPointRate).plus(borrowIncentiveAccount.points).multipliedBy(borrowIncentivePool.exchangeRateNumerator).dividedBy(borrowIncentivePool.exchangeRateDenominator)
|
|
2415
|
+
);
|
|
2416
|
+
availableClaimCoin = availableClaimAmount.shiftedBy(
|
|
2417
|
+
-1 * borrowIncentivePool.rewardCoinDecimal
|
|
2418
|
+
);
|
|
2419
|
+
if (availableClaimAmount.isGreaterThan(0)) {
|
|
2420
|
+
borrowIncentives[coinName] = {
|
|
2421
|
+
coinName: borrowIncentivePool.coinName,
|
|
2422
|
+
coinType: borrowIncentivePool.coinType,
|
|
2423
|
+
rewardCoinType: borrowIncentivePool.rewardCoinType,
|
|
2424
|
+
symbol: borrowIncentivePool.symbol,
|
|
2425
|
+
coinDecimal: borrowIncentivePool.coinDecimal,
|
|
2426
|
+
rewardCoinDecimal: borrowIncentivePool.rewardCoinDecimal,
|
|
2427
|
+
coinPrice: borrowIncentivePool.coinPrice,
|
|
2428
|
+
rewardCoinPrice: borrowIncentivePool.rewardCoinPrice,
|
|
2429
|
+
availableClaimAmount: availableClaimAmount.toNumber(),
|
|
2430
|
+
availableClaimCoin: availableClaimCoin.toNumber()
|
|
2431
|
+
};
|
|
2432
|
+
}
|
|
2433
|
+
}
|
|
2434
|
+
}
|
|
2112
2435
|
let riskLevel = totalRequiredCollateralValue.isZero() && totalBorrowedValueWithWeight.isZero() ? (0, import_bignumber3.default)(0) : totalBorrowedValueWithWeight.dividedBy(totalRequiredCollateralValue);
|
|
2113
2436
|
riskLevel = riskLevel.isFinite() ? riskLevel.isLessThan(1) ? riskLevel : (0, import_bignumber3.default)(1) : (0, import_bignumber3.default)(1);
|
|
2114
2437
|
const accountBalanceValue = totalDepositedValue.minus(totalBorrowedValue).isGreaterThan(0) ? totalDepositedValue.minus(totalBorrowedValue) : (0, import_bignumber3.default)(0);
|
|
@@ -2137,7 +2460,8 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
|
|
|
2137
2460
|
totalDepositedPools,
|
|
2138
2461
|
totalBorrowedPools,
|
|
2139
2462
|
collaterals,
|
|
2140
|
-
debts
|
|
2463
|
+
debts,
|
|
2464
|
+
borrowIncentives
|
|
2141
2465
|
};
|
|
2142
2466
|
for (const [collateralCoinName, obligationCollateral] of Object.entries(
|
|
2143
2467
|
obligationAccount.collaterals
|
|
@@ -2153,10 +2477,10 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
|
|
|
2153
2477
|
obligationCollateral.availableWithdrawCoin = availableWithdrawAmount.shiftedBy(-1 * obligationCollateral.coinDecimal).toNumber();
|
|
2154
2478
|
}
|
|
2155
2479
|
}
|
|
2156
|
-
for (const [
|
|
2480
|
+
for (const [poolCoinName, obligationDebt] of Object.entries(
|
|
2157
2481
|
obligationAccount.debts
|
|
2158
2482
|
)) {
|
|
2159
|
-
const marketPool = market.pools[
|
|
2483
|
+
const marketPool = market.pools[poolCoinName];
|
|
2160
2484
|
if (marketPool) {
|
|
2161
2485
|
const availableRepayAmount = (0, import_bignumber3.default)(
|
|
2162
2486
|
obligationDebt.availableRepayAmount
|
|
@@ -2206,7 +2530,7 @@ var getTotalValueLocked = async (query) => {
|
|
|
2206
2530
|
var ScallopQuery = class {
|
|
2207
2531
|
constructor(params, instance) {
|
|
2208
2532
|
this.params = params;
|
|
2209
|
-
this.suiKit = instance?.suiKit ?? new
|
|
2533
|
+
this.suiKit = instance?.suiKit ?? new import_sui_kit3.SuiKit(params);
|
|
2210
2534
|
this.address = instance?.address ?? new ScallopAddress({
|
|
2211
2535
|
id: params?.addressesId || ADDRESSES_ID,
|
|
2212
2536
|
network: params?.networkType
|
|
@@ -2422,38 +2746,60 @@ var ScallopQuery = class {
|
|
|
2422
2746
|
return await getStakePool(this, stakeMarketCoinName);
|
|
2423
2747
|
}
|
|
2424
2748
|
/**
|
|
2425
|
-
* Get reward pools data.
|
|
2749
|
+
* Get stake reward pools data.
|
|
2426
2750
|
*
|
|
2427
2751
|
* @description
|
|
2428
2752
|
* For backward compatible, it is recommended to use `getSpools` method
|
|
2429
2753
|
* to get all spools data.
|
|
2430
2754
|
*
|
|
2431
2755
|
* @param stakeMarketCoinNames - Specific an array of stake market coin name.
|
|
2432
|
-
* @return
|
|
2756
|
+
* @return Stake reward pools data.
|
|
2433
2757
|
*/
|
|
2434
|
-
async
|
|
2758
|
+
async getStakeRewardPools(stakeMarketCoinNames) {
|
|
2435
2759
|
stakeMarketCoinNames = stakeMarketCoinNames ?? [...SUPPORT_SPOOLS];
|
|
2436
|
-
const
|
|
2760
|
+
const stakeRewardPools = {};
|
|
2437
2761
|
for (const stakeMarketCoinName of stakeMarketCoinNames) {
|
|
2438
|
-
const
|
|
2439
|
-
|
|
2440
|
-
|
|
2762
|
+
const stakeRewardPool = await getStakeRewardPool(
|
|
2763
|
+
this,
|
|
2764
|
+
stakeMarketCoinName
|
|
2765
|
+
);
|
|
2766
|
+
if (stakeRewardPool) {
|
|
2767
|
+
stakeRewardPools[stakeMarketCoinName] = stakeRewardPool;
|
|
2441
2768
|
}
|
|
2442
2769
|
}
|
|
2443
|
-
return
|
|
2770
|
+
return stakeRewardPools;
|
|
2444
2771
|
}
|
|
2445
2772
|
/**
|
|
2446
|
-
* Get reward pool data.
|
|
2773
|
+
* Get stake reward pool data.
|
|
2447
2774
|
*
|
|
2448
2775
|
* @description
|
|
2449
2776
|
* For backward compatible, it is recommended to use `getSpool` method
|
|
2450
2777
|
* to get spool data.
|
|
2451
2778
|
*
|
|
2452
2779
|
* @param marketCoinName - Specific support stake market coin name.
|
|
2453
|
-
* @return
|
|
2780
|
+
* @return Stake reward pool data.
|
|
2781
|
+
*/
|
|
2782
|
+
async getStakeRewardPool(stakeMarketCoinName) {
|
|
2783
|
+
return await getStakeRewardPool(this, stakeMarketCoinName);
|
|
2784
|
+
}
|
|
2785
|
+
/**
|
|
2786
|
+
* Get borrow incentive pools data.
|
|
2787
|
+
*
|
|
2788
|
+
* @param coinNames - Specific an array of support borrow incentive coin name.
|
|
2789
|
+
* @return Borrow incentive pools data.
|
|
2790
|
+
*/
|
|
2791
|
+
async getBorrowIncentivePools(coinNames) {
|
|
2792
|
+
return await queryBorrowIncentivePools(this, coinNames);
|
|
2793
|
+
}
|
|
2794
|
+
/**
|
|
2795
|
+
* Get borrow incentive accounts data.
|
|
2796
|
+
*
|
|
2797
|
+
* @param coinNames - Specific support borrow incentive coin name.
|
|
2798
|
+
* @param ownerAddress - The owner address.
|
|
2799
|
+
* @return Borrow incentive accounts data.
|
|
2454
2800
|
*/
|
|
2455
|
-
async
|
|
2456
|
-
return await
|
|
2801
|
+
async getBorrowIncentiveAccounts(obligationId, coinNames) {
|
|
2802
|
+
return await queryBorrowIncentiveAccounts(this, obligationId, coinNames);
|
|
2457
2803
|
}
|
|
2458
2804
|
/**
|
|
2459
2805
|
* Get user lending and spool infomation for specific pools.
|
|
@@ -2517,16 +2863,25 @@ var ScallopUtils = class {
|
|
|
2517
2863
|
constructor(params, instance) {
|
|
2518
2864
|
this._priceMap = /* @__PURE__ */ new Map();
|
|
2519
2865
|
/**
|
|
2520
|
-
* Get reward type of
|
|
2866
|
+
* Get reward type of spool.
|
|
2521
2867
|
*
|
|
2522
2868
|
* @param stakeMarketCoinName - Support stake market coin.
|
|
2523
|
-
* @return
|
|
2869
|
+
* @return Spool reward coin name.
|
|
2524
2870
|
*/
|
|
2525
|
-
this.
|
|
2526
|
-
return
|
|
2871
|
+
this.getSpoolRewardCoinName = (stakeMarketCoinName) => {
|
|
2872
|
+
return spoolRewardCoins[stakeMarketCoinName];
|
|
2873
|
+
};
|
|
2874
|
+
/**
|
|
2875
|
+
* Get reward type of borrow incentive pool.
|
|
2876
|
+
*
|
|
2877
|
+
* @param borrowIncentiveCoinName - Support borrow incentive coin.
|
|
2878
|
+
* @return Borrow incentive reward coin name.
|
|
2879
|
+
*/
|
|
2880
|
+
this.getBorrowIncentiveRewardCoinName = (borrowIncentiveCoinName) => {
|
|
2881
|
+
return borrowIncentiveRewardCoins[borrowIncentiveCoinName];
|
|
2527
2882
|
};
|
|
2528
2883
|
this.params = params;
|
|
2529
|
-
this._suiKit = instance?.suiKit ?? new
|
|
2884
|
+
this._suiKit = instance?.suiKit ?? new import_sui_kit4.SuiKit(params);
|
|
2530
2885
|
this._address = instance?.address ?? new ScallopAddress({
|
|
2531
2886
|
id: params?.addressesId || ADDRESSES_ID,
|
|
2532
2887
|
network: params?.networkType
|
|
@@ -2580,7 +2935,7 @@ var ScallopUtils = class {
|
|
|
2580
2935
|
throw Error(`Coin ${coinName} is not supported`);
|
|
2581
2936
|
}
|
|
2582
2937
|
if (coinName === "sui")
|
|
2583
|
-
return (0,
|
|
2938
|
+
return (0, import_utils9.normalizeStructTag)(`${coinPackageId}::sui::SUI`);
|
|
2584
2939
|
const wormHolePckageIds = [
|
|
2585
2940
|
this._address.get("core.coins.usdc.id") ?? wormholeCoinIds.usdc,
|
|
2586
2941
|
this._address.get("core.coins.usdt.id") ?? wormholeCoinIds.usdt,
|
|
@@ -2612,7 +2967,7 @@ var ScallopUtils = class {
|
|
|
2612
2967
|
return `${PROTOCOL_OBJECT_ID}::reserve::MarketCoin<${coinType}>`;
|
|
2613
2968
|
}
|
|
2614
2969
|
parseCoinNameFromType(coinType) {
|
|
2615
|
-
coinType = (0,
|
|
2970
|
+
coinType = (0, import_utils9.normalizeStructTag)(coinType);
|
|
2616
2971
|
const coinTypeRegex = new RegExp(`((0x[^:]+::[^:]+::[^<>]+))(?![^<>]*<)`);
|
|
2617
2972
|
const coinTypeMatch = coinType.match(coinTypeRegex);
|
|
2618
2973
|
const isMarketCoinType = coinType.includes("reserve::MarketCoin");
|
|
@@ -2676,7 +3031,7 @@ var ScallopUtils = class {
|
|
|
2676
3031
|
* @param coinType - The coin type, default is 0x2::SUI::SUI.
|
|
2677
3032
|
* @return The selected transaction coin arguments.
|
|
2678
3033
|
*/
|
|
2679
|
-
async selectCoinIds(amount, coinType =
|
|
3034
|
+
async selectCoinIds(amount, coinType = import_utils9.SUI_TYPE_ARG, ownerAddress) {
|
|
2680
3035
|
ownerAddress = ownerAddress || this._suiKit.currentAddress();
|
|
2681
3036
|
const coins = await this._suiKit.suiInteractor.selectCoins(
|
|
2682
3037
|
ownerAddress,
|
|
@@ -2796,16 +3151,16 @@ var ScallopUtils = class {
|
|
|
2796
3151
|
};
|
|
2797
3152
|
|
|
2798
3153
|
// src/models/scallopBuilder.ts
|
|
2799
|
-
var
|
|
2800
|
-
var
|
|
3154
|
+
var import_utils18 = require("@mysten/sui.js/utils");
|
|
3155
|
+
var import_sui_kit8 = require("@scallop-io/sui-kit");
|
|
2801
3156
|
|
|
2802
3157
|
// src/builders/coreBuilder.ts
|
|
2803
3158
|
var import_transactions = require("@mysten/sui.js/transactions");
|
|
2804
|
-
var
|
|
2805
|
-
var
|
|
3159
|
+
var import_utils12 = require("@mysten/sui.js/utils");
|
|
3160
|
+
var import_sui_kit5 = require("@scallop-io/sui-kit");
|
|
2806
3161
|
|
|
2807
3162
|
// src/builders/oracle.ts
|
|
2808
|
-
var
|
|
3163
|
+
var import_utils11 = require("@mysten/sui.js/utils");
|
|
2809
3164
|
var import_pyth_sui_js2 = require("@pythnetwork/pyth-sui-js");
|
|
2810
3165
|
var updateOracles = async (builder, txBlock, assetCoinNames) => {
|
|
2811
3166
|
assetCoinNames = assetCoinNames ?? [
|
|
@@ -2911,39 +3266,32 @@ var priceUpdateRequest = (txBlock, packageId, xOracleId, coinType) => {
|
|
|
2911
3266
|
var confirmPriceUpdateRequest = (txBlock, packageId, xOracleId, request, coinType) => {
|
|
2912
3267
|
const target = `${packageId}::x_oracle::confirm_price_update_request`;
|
|
2913
3268
|
const typeArgs = [coinType];
|
|
2914
|
-
txBlock.moveCall(target, [xOracleId, request,
|
|
3269
|
+
txBlock.moveCall(target, [xOracleId, request, import_utils11.SUI_CLOCK_OBJECT_ID], typeArgs);
|
|
2915
3270
|
return txBlock;
|
|
2916
3271
|
};
|
|
2917
3272
|
var updateSupraPrice = (txBlock, packageId, request, holderId, registryId, coinType) => {
|
|
2918
3273
|
txBlock.moveCall(
|
|
2919
3274
|
`${packageId}::rule::set_price`,
|
|
2920
|
-
[request, holderId, registryId,
|
|
3275
|
+
[request, holderId, registryId, import_utils11.SUI_CLOCK_OBJECT_ID],
|
|
2921
3276
|
[coinType]
|
|
2922
3277
|
);
|
|
2923
3278
|
};
|
|
2924
3279
|
var updateSwitchboardPrice = (txBlock, packageId, request, aggregatorId, registryId, coinType) => {
|
|
2925
3280
|
txBlock.moveCall(
|
|
2926
3281
|
`${packageId}::rule::set_price`,
|
|
2927
|
-
[request, aggregatorId, registryId,
|
|
3282
|
+
[request, aggregatorId, registryId, import_utils11.SUI_CLOCK_OBJECT_ID],
|
|
2928
3283
|
[coinType]
|
|
2929
3284
|
);
|
|
2930
3285
|
};
|
|
2931
3286
|
var updatePythPrice = (txBlock, packageId, request, stateId, feedObjectId, registryId, coinType) => {
|
|
2932
3287
|
txBlock.moveCall(
|
|
2933
3288
|
`${packageId}::rule::set_price`,
|
|
2934
|
-
[request, stateId, feedObjectId, registryId,
|
|
3289
|
+
[request, stateId, feedObjectId, registryId, import_utils11.SUI_CLOCK_OBJECT_ID],
|
|
2935
3290
|
[coinType]
|
|
2936
3291
|
);
|
|
2937
3292
|
};
|
|
2938
3293
|
|
|
2939
3294
|
// src/builders/coreBuilder.ts
|
|
2940
|
-
var requireSender = (txBlock) => {
|
|
2941
|
-
const sender = txBlock.blockData.sender;
|
|
2942
|
-
if (!sender) {
|
|
2943
|
-
throw new Error("Sender is required");
|
|
2944
|
-
}
|
|
2945
|
-
return sender;
|
|
2946
|
-
};
|
|
2947
3295
|
var requireObligationInfo = async (...params) => {
|
|
2948
3296
|
const [builder, txBlock, obligationId, obligationKey] = params;
|
|
2949
3297
|
if (params.length === 3 && obligationId)
|
|
@@ -3004,7 +3352,7 @@ var generateCoreNormalMethod = ({
|
|
|
3004
3352
|
coreIds.coinDecimalsRegistry,
|
|
3005
3353
|
amount,
|
|
3006
3354
|
coreIds.xOracle,
|
|
3007
|
-
|
|
3355
|
+
import_utils12.SUI_CLOCK_OBJECT_ID
|
|
3008
3356
|
],
|
|
3009
3357
|
[coinType]
|
|
3010
3358
|
);
|
|
@@ -3013,7 +3361,7 @@ var generateCoreNormalMethod = ({
|
|
|
3013
3361
|
const coinType = builder.utils.parseCoinType(poolCoinName);
|
|
3014
3362
|
return txBlock.moveCall(
|
|
3015
3363
|
`${coreIds.protocolPkg}::mint::mint`,
|
|
3016
|
-
[coreIds.version, coreIds.market, coin,
|
|
3364
|
+
[coreIds.version, coreIds.market, coin, import_utils12.SUI_CLOCK_OBJECT_ID],
|
|
3017
3365
|
[coinType]
|
|
3018
3366
|
);
|
|
3019
3367
|
},
|
|
@@ -3021,7 +3369,7 @@ var generateCoreNormalMethod = ({
|
|
|
3021
3369
|
const coinType = builder.utils.parseCoinType(poolCoinName);
|
|
3022
3370
|
return txBlock.moveCall(
|
|
3023
3371
|
`${coreIds.protocolPkg}::mint::mint_entry`,
|
|
3024
|
-
[coreIds.version, coreIds.market, coin,
|
|
3372
|
+
[coreIds.version, coreIds.market, coin, import_utils12.SUI_CLOCK_OBJECT_ID],
|
|
3025
3373
|
[coinType]
|
|
3026
3374
|
);
|
|
3027
3375
|
},
|
|
@@ -3029,7 +3377,7 @@ var generateCoreNormalMethod = ({
|
|
|
3029
3377
|
const coinType = builder.utils.parseCoinType(poolCoinName);
|
|
3030
3378
|
return txBlock.moveCall(
|
|
3031
3379
|
`${coreIds.protocolPkg}::redeem::redeem`,
|
|
3032
|
-
[coreIds.version, coreIds.market, marketCoin,
|
|
3380
|
+
[coreIds.version, coreIds.market, marketCoin, import_utils12.SUI_CLOCK_OBJECT_ID],
|
|
3033
3381
|
[coinType]
|
|
3034
3382
|
);
|
|
3035
3383
|
},
|
|
@@ -3037,7 +3385,7 @@ var generateCoreNormalMethod = ({
|
|
|
3037
3385
|
const coinType = builder.utils.parseCoinType(poolCoinName);
|
|
3038
3386
|
return txBlock.moveCall(
|
|
3039
3387
|
`${coreIds.protocolPkg}::redeem::redeem_entry`,
|
|
3040
|
-
[coreIds.version, coreIds.market, marketCoin,
|
|
3388
|
+
[coreIds.version, coreIds.market, marketCoin, import_utils12.SUI_CLOCK_OBJECT_ID],
|
|
3041
3389
|
[coinType]
|
|
3042
3390
|
);
|
|
3043
3391
|
},
|
|
@@ -3053,7 +3401,7 @@ var generateCoreNormalMethod = ({
|
|
|
3053
3401
|
coreIds.coinDecimalsRegistry,
|
|
3054
3402
|
amount,
|
|
3055
3403
|
coreIds.xOracle,
|
|
3056
|
-
|
|
3404
|
+
import_utils12.SUI_CLOCK_OBJECT_ID
|
|
3057
3405
|
],
|
|
3058
3406
|
[coinType]
|
|
3059
3407
|
);
|
|
@@ -3070,7 +3418,7 @@ var generateCoreNormalMethod = ({
|
|
|
3070
3418
|
coreIds.coinDecimalsRegistry,
|
|
3071
3419
|
amount,
|
|
3072
3420
|
coreIds.xOracle,
|
|
3073
|
-
|
|
3421
|
+
import_utils12.SUI_CLOCK_OBJECT_ID
|
|
3074
3422
|
],
|
|
3075
3423
|
[coinType]
|
|
3076
3424
|
);
|
|
@@ -3084,7 +3432,7 @@ var generateCoreNormalMethod = ({
|
|
|
3084
3432
|
obligation,
|
|
3085
3433
|
coreIds.market,
|
|
3086
3434
|
coin,
|
|
3087
|
-
|
|
3435
|
+
import_utils12.SUI_CLOCK_OBJECT_ID
|
|
3088
3436
|
],
|
|
3089
3437
|
[coinType]
|
|
3090
3438
|
);
|
|
@@ -3233,7 +3581,7 @@ var generateCoreQuickMethod = ({
|
|
|
3233
3581
|
};
|
|
3234
3582
|
};
|
|
3235
3583
|
var newCoreTxBlock = (builder, initTxBlock) => {
|
|
3236
|
-
const txBlock = initTxBlock instanceof import_transactions.TransactionBlock ? new
|
|
3584
|
+
const txBlock = initTxBlock instanceof import_transactions.TransactionBlock ? new import_sui_kit5.SuiTxBlock(initTxBlock) : initTxBlock ? initTxBlock : new import_sui_kit5.SuiTxBlock();
|
|
3237
3585
|
const normalMethod = generateCoreNormalMethod({
|
|
3238
3586
|
builder,
|
|
3239
3587
|
txBlock
|
|
@@ -3262,20 +3610,13 @@ var newCoreTxBlock = (builder, initTxBlock) => {
|
|
|
3262
3610
|
|
|
3263
3611
|
// src/builders/spoolBuilder.ts
|
|
3264
3612
|
var import_transactions2 = require("@mysten/sui.js/transactions");
|
|
3265
|
-
var
|
|
3266
|
-
var
|
|
3267
|
-
var requireSender2 = (txBlock) => {
|
|
3268
|
-
const sender = txBlock.blockData.sender;
|
|
3269
|
-
if (!sender) {
|
|
3270
|
-
throw new Error("Sender is required");
|
|
3271
|
-
}
|
|
3272
|
-
return sender;
|
|
3273
|
-
};
|
|
3613
|
+
var import_utils14 = require("@mysten/sui.js/utils");
|
|
3614
|
+
var import_sui_kit6 = require("@scallop-io/sui-kit");
|
|
3274
3615
|
var requireStakeAccountIds = async (...params) => {
|
|
3275
3616
|
const [builder, txBlock, stakeMarketCoinName, stakeAccountId] = params;
|
|
3276
3617
|
if (params.length === 4 && stakeAccountId)
|
|
3277
3618
|
return [stakeAccountId];
|
|
3278
|
-
const sender =
|
|
3619
|
+
const sender = requireSender(txBlock);
|
|
3279
3620
|
const stakeAccounts = await getStakeAccounts(builder.query, sender);
|
|
3280
3621
|
if (stakeAccounts[stakeMarketCoinName].length === 0) {
|
|
3281
3622
|
throw new Error(`No stake account id found for sender ${sender}`);
|
|
@@ -3284,7 +3625,7 @@ var requireStakeAccountIds = async (...params) => {
|
|
|
3284
3625
|
};
|
|
3285
3626
|
var requireStakeAccounts = async (...params) => {
|
|
3286
3627
|
const [builder, txBlock, stakeMarketCoinName, stakeAccountId] = params;
|
|
3287
|
-
const sender =
|
|
3628
|
+
const sender = requireSender(txBlock);
|
|
3288
3629
|
const stakeAccounts = await getStakeAccounts(builder.query, sender);
|
|
3289
3630
|
if (stakeAccounts[stakeMarketCoinName].length === 0) {
|
|
3290
3631
|
throw new Error(`No stake account found for sender ${sender}`);
|
|
@@ -3309,7 +3650,7 @@ var generateSpoolNormalMethod = ({
|
|
|
3309
3650
|
);
|
|
3310
3651
|
return txBlock.moveCall(
|
|
3311
3652
|
`${spoolIds.spoolPkg}::user::new_spool_account`,
|
|
3312
|
-
[stakePoolId,
|
|
3653
|
+
[stakePoolId, import_utils14.SUI_CLOCK_OBJECT_ID],
|
|
3313
3654
|
[marketCoinType]
|
|
3314
3655
|
);
|
|
3315
3656
|
},
|
|
@@ -3320,7 +3661,7 @@ var generateSpoolNormalMethod = ({
|
|
|
3320
3661
|
);
|
|
3321
3662
|
txBlock.moveCall(
|
|
3322
3663
|
`${spoolIds.spoolPkg}::user::stake`,
|
|
3323
|
-
[stakePoolId, stakeAccount, coin,
|
|
3664
|
+
[stakePoolId, stakeAccount, coin, import_utils14.SUI_CLOCK_OBJECT_ID],
|
|
3324
3665
|
[marketCoinType]
|
|
3325
3666
|
);
|
|
3326
3667
|
},
|
|
@@ -3331,7 +3672,7 @@ var generateSpoolNormalMethod = ({
|
|
|
3331
3672
|
);
|
|
3332
3673
|
return txBlock.moveCall(
|
|
3333
3674
|
`${spoolIds.spoolPkg}::user::unstake`,
|
|
3334
|
-
[stakePoolId, stakeAccount, amount,
|
|
3675
|
+
[stakePoolId, stakeAccount, amount, import_utils14.SUI_CLOCK_OBJECT_ID],
|
|
3335
3676
|
[marketCoinType]
|
|
3336
3677
|
);
|
|
3337
3678
|
},
|
|
@@ -3343,11 +3684,11 @@ var generateSpoolNormalMethod = ({
|
|
|
3343
3684
|
`spool.pools.${stakeMarketCoinName}.rewardPoolId`
|
|
3344
3685
|
);
|
|
3345
3686
|
const marketCoinType = builder.utils.parseMarketCoinType(stakeMarketCoinName);
|
|
3346
|
-
const rewardCoinName =
|
|
3687
|
+
const rewardCoinName = spoolRewardCoins[stakeMarketCoinName];
|
|
3347
3688
|
const rewardCoinType = builder.utils.parseCoinType(rewardCoinName);
|
|
3348
3689
|
return txBlock.moveCall(
|
|
3349
3690
|
`${spoolIds.spoolPkg}::user::redeem_rewards`,
|
|
3350
|
-
[stakePoolId, rewardPoolId, stakeAccount,
|
|
3691
|
+
[stakePoolId, rewardPoolId, stakeAccount, import_utils14.SUI_CLOCK_OBJECT_ID],
|
|
3351
3692
|
[marketCoinType, rewardCoinType]
|
|
3352
3693
|
);
|
|
3353
3694
|
}
|
|
@@ -3359,7 +3700,7 @@ var generateSpoolQuickMethod = ({
|
|
|
3359
3700
|
}) => {
|
|
3360
3701
|
return {
|
|
3361
3702
|
stakeQuick: async (amountOrMarketCoin, stakeMarketCoinName, stakeAccountId) => {
|
|
3362
|
-
const sender =
|
|
3703
|
+
const sender = requireSender(txBlock);
|
|
3363
3704
|
const stakeAccountIds = await requireStakeAccountIds(
|
|
3364
3705
|
builder,
|
|
3365
3706
|
txBlock,
|
|
@@ -3418,17 +3759,17 @@ var generateSpoolQuickMethod = ({
|
|
|
3418
3759
|
stakeMarketCoinName,
|
|
3419
3760
|
stakeAccountId
|
|
3420
3761
|
);
|
|
3421
|
-
const
|
|
3762
|
+
const rewardCoins = [];
|
|
3422
3763
|
for (const accountId of stakeAccountIds) {
|
|
3423
3764
|
const rewardCoin = txBlock.claim(accountId, stakeMarketCoinName);
|
|
3424
|
-
|
|
3765
|
+
rewardCoins.push(rewardCoin);
|
|
3425
3766
|
}
|
|
3426
|
-
return
|
|
3767
|
+
return rewardCoins;
|
|
3427
3768
|
}
|
|
3428
3769
|
};
|
|
3429
3770
|
};
|
|
3430
3771
|
var newSpoolTxBlock = (builder, initTxBlock) => {
|
|
3431
|
-
const txBlock = initTxBlock instanceof import_transactions2.TransactionBlock ? new
|
|
3772
|
+
const txBlock = initTxBlock instanceof import_transactions2.TransactionBlock ? new import_sui_kit6.SuiTxBlock(initTxBlock) : initTxBlock ? initTxBlock : new import_sui_kit6.SuiTxBlock();
|
|
3432
3773
|
const normalMethod = generateSpoolNormalMethod({
|
|
3433
3774
|
builder,
|
|
3434
3775
|
txBlock
|
|
@@ -3455,13 +3796,183 @@ var newSpoolTxBlock = (builder, initTxBlock) => {
|
|
|
3455
3796
|
});
|
|
3456
3797
|
};
|
|
3457
3798
|
|
|
3799
|
+
// src/builders/borrowIncentiveBuilder.ts
|
|
3800
|
+
var import_transactions3 = require("@mysten/sui.js/transactions");
|
|
3801
|
+
var import_utils16 = require("@mysten/sui.js/utils");
|
|
3802
|
+
var import_sui_kit7 = require("@scallop-io/sui-kit");
|
|
3803
|
+
var requireObligationInfo2 = async (...params) => {
|
|
3804
|
+
const [builder, txBlock, obligationId, obligationKey] = params;
|
|
3805
|
+
if (params.length === 4 && obligationId && obligationKey && typeof obligationId === "string") {
|
|
3806
|
+
const obligationLocked = await getObligationLocked(
|
|
3807
|
+
builder.query,
|
|
3808
|
+
obligationId
|
|
3809
|
+
);
|
|
3810
|
+
return { obligationId, obligationKey, obligationLocked };
|
|
3811
|
+
}
|
|
3812
|
+
const sender = requireSender(txBlock);
|
|
3813
|
+
const obligations = await getObligations(builder.query, sender);
|
|
3814
|
+
if (obligations.length === 0) {
|
|
3815
|
+
throw new Error(`No obligation found for sender ${sender}`);
|
|
3816
|
+
}
|
|
3817
|
+
return {
|
|
3818
|
+
obligationId: obligations[0].id,
|
|
3819
|
+
obligationKey: obligations[0].keyId,
|
|
3820
|
+
obligationLocked: obligations[0].locked
|
|
3821
|
+
};
|
|
3822
|
+
};
|
|
3823
|
+
var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
|
|
3824
|
+
const borrowIncentiveIds = {
|
|
3825
|
+
borrowIncentivePkg: builder.address.get("borrowIncentive.id"),
|
|
3826
|
+
query: builder.address.get("borrowIncentive.query"),
|
|
3827
|
+
incentivePools: builder.address.get("borrowIncentive.incentivePools"),
|
|
3828
|
+
incentiveAccounts: builder.address.get(
|
|
3829
|
+
"borrowIncentive.incentiveAccounts"
|
|
3830
|
+
),
|
|
3831
|
+
obligationAccessStore: builder.address.get("core.obligationAccessStore")
|
|
3832
|
+
};
|
|
3833
|
+
return {
|
|
3834
|
+
stakeObligation: (obligationId, obligaionKey, coinName) => {
|
|
3835
|
+
const rewardCoinName = borrowIncentiveRewardCoins[coinName];
|
|
3836
|
+
const rewardType = builder.utils.parseCoinType(rewardCoinName);
|
|
3837
|
+
txBlock.moveCall(
|
|
3838
|
+
`${borrowIncentiveIds.borrowIncentivePkg}::user::stake`,
|
|
3839
|
+
[
|
|
3840
|
+
borrowIncentiveIds.incentivePools,
|
|
3841
|
+
borrowIncentiveIds.incentiveAccounts,
|
|
3842
|
+
obligaionKey,
|
|
3843
|
+
obligationId,
|
|
3844
|
+
borrowIncentiveIds.obligationAccessStore,
|
|
3845
|
+
import_utils16.SUI_CLOCK_OBJECT_ID
|
|
3846
|
+
],
|
|
3847
|
+
[rewardType]
|
|
3848
|
+
);
|
|
3849
|
+
},
|
|
3850
|
+
unstakeObligation: (obligationId, obligaionKey, coinName) => {
|
|
3851
|
+
const rewardCoinName = borrowIncentiveRewardCoins[coinName];
|
|
3852
|
+
const rewardType = builder.utils.parseCoinType(rewardCoinName);
|
|
3853
|
+
txBlock.moveCall(
|
|
3854
|
+
`${borrowIncentiveIds.borrowIncentivePkg}::user::unstake`,
|
|
3855
|
+
[
|
|
3856
|
+
borrowIncentiveIds.incentivePools,
|
|
3857
|
+
borrowIncentiveIds.incentiveAccounts,
|
|
3858
|
+
obligaionKey,
|
|
3859
|
+
obligationId,
|
|
3860
|
+
import_utils16.SUI_CLOCK_OBJECT_ID
|
|
3861
|
+
],
|
|
3862
|
+
[rewardType]
|
|
3863
|
+
);
|
|
3864
|
+
},
|
|
3865
|
+
claimBorrowIncentive: (obligationId, obligaionKey, coinName) => {
|
|
3866
|
+
const rewardCoinName = borrowIncentiveRewardCoins[coinName];
|
|
3867
|
+
const rewardType = builder.utils.parseCoinType(rewardCoinName);
|
|
3868
|
+
return txBlock.moveCall(
|
|
3869
|
+
`${borrowIncentiveIds.borrowIncentivePkg}::user::redeem_rewards`,
|
|
3870
|
+
[
|
|
3871
|
+
borrowIncentiveIds.incentivePools,
|
|
3872
|
+
borrowIncentiveIds.incentiveAccounts,
|
|
3873
|
+
obligaionKey,
|
|
3874
|
+
obligationId,
|
|
3875
|
+
import_utils16.SUI_CLOCK_OBJECT_ID
|
|
3876
|
+
],
|
|
3877
|
+
[rewardType]
|
|
3878
|
+
);
|
|
3879
|
+
}
|
|
3880
|
+
};
|
|
3881
|
+
};
|
|
3882
|
+
var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
|
|
3883
|
+
return {
|
|
3884
|
+
stakeObligationQuick: async (coinName, obligation, obligationKey) => {
|
|
3885
|
+
const {
|
|
3886
|
+
obligationId: obligationArg,
|
|
3887
|
+
obligationKey: obligationtKeyArg,
|
|
3888
|
+
obligationLocked
|
|
3889
|
+
} = await requireObligationInfo2(
|
|
3890
|
+
builder,
|
|
3891
|
+
txBlock,
|
|
3892
|
+
obligation,
|
|
3893
|
+
obligationKey
|
|
3894
|
+
);
|
|
3895
|
+
const unstakeObligationBeforeStake = !!txBlock.txBlock.blockData.transactions.find(
|
|
3896
|
+
(txn) => txn.kind === "MoveCall" && txn.target === `${builder.address.get("borrowIncentive.id")}::user::unstake`
|
|
3897
|
+
);
|
|
3898
|
+
if (!obligationLocked || unstakeObligationBeforeStake) {
|
|
3899
|
+
txBlock.stakeObligation(obligationArg, obligationtKeyArg, coinName);
|
|
3900
|
+
}
|
|
3901
|
+
},
|
|
3902
|
+
unstakeObligationQuick: async (coinName, obligation, obligationKey) => {
|
|
3903
|
+
const {
|
|
3904
|
+
obligationId: obligationArg,
|
|
3905
|
+
obligationKey: obligationtKeyArg,
|
|
3906
|
+
obligationLocked
|
|
3907
|
+
} = await requireObligationInfo2(
|
|
3908
|
+
builder,
|
|
3909
|
+
txBlock,
|
|
3910
|
+
obligation,
|
|
3911
|
+
obligationKey
|
|
3912
|
+
);
|
|
3913
|
+
if (obligationLocked) {
|
|
3914
|
+
txBlock.unstakeObligation(obligationArg, obligationtKeyArg, coinName);
|
|
3915
|
+
}
|
|
3916
|
+
},
|
|
3917
|
+
claimBorrowIncentiveQuick: async (coinName, obligation, obligationKey) => {
|
|
3918
|
+
const {
|
|
3919
|
+
obligationId: obligationArg,
|
|
3920
|
+
obligationKey: obligationtKeyArg
|
|
3921
|
+
} = await requireObligationInfo2(
|
|
3922
|
+
builder,
|
|
3923
|
+
txBlock,
|
|
3924
|
+
obligation,
|
|
3925
|
+
obligationKey
|
|
3926
|
+
);
|
|
3927
|
+
return txBlock.claimBorrowIncentive(
|
|
3928
|
+
obligationArg,
|
|
3929
|
+
obligationtKeyArg,
|
|
3930
|
+
coinName
|
|
3931
|
+
);
|
|
3932
|
+
}
|
|
3933
|
+
};
|
|
3934
|
+
};
|
|
3935
|
+
var newBorrowIncentiveTxBlock = (builder, initTxBlock) => {
|
|
3936
|
+
const txBlock = initTxBlock instanceof import_transactions3.TransactionBlock ? new import_sui_kit7.SuiTxBlock(initTxBlock) : initTxBlock ? initTxBlock : new import_sui_kit7.SuiTxBlock();
|
|
3937
|
+
const normalMethod = generateBorrowIncentiveNormalMethod({
|
|
3938
|
+
builder,
|
|
3939
|
+
txBlock
|
|
3940
|
+
});
|
|
3941
|
+
const normalTxBlock = new Proxy(txBlock, {
|
|
3942
|
+
get: (target, prop) => {
|
|
3943
|
+
if (prop in normalMethod) {
|
|
3944
|
+
return Reflect.get(normalMethod, prop);
|
|
3945
|
+
}
|
|
3946
|
+
return Reflect.get(target, prop);
|
|
3947
|
+
}
|
|
3948
|
+
});
|
|
3949
|
+
const quickMethod = generateBorrowIncentiveQuickMethod({
|
|
3950
|
+
builder,
|
|
3951
|
+
txBlock: normalTxBlock
|
|
3952
|
+
});
|
|
3953
|
+
return new Proxy(normalTxBlock, {
|
|
3954
|
+
get: (target, prop) => {
|
|
3955
|
+
if (prop in quickMethod) {
|
|
3956
|
+
return Reflect.get(quickMethod, prop);
|
|
3957
|
+
}
|
|
3958
|
+
return Reflect.get(target, prop);
|
|
3959
|
+
}
|
|
3960
|
+
});
|
|
3961
|
+
};
|
|
3962
|
+
|
|
3458
3963
|
// src/builders/index.ts
|
|
3459
3964
|
var newScallopTxBlock = (builder, initTxBlock) => {
|
|
3460
|
-
const
|
|
3965
|
+
const borrowIncentiveTxBlock = newBorrowIncentiveTxBlock(
|
|
3966
|
+
builder,
|
|
3967
|
+
initTxBlock
|
|
3968
|
+
);
|
|
3969
|
+
const spoolTxBlock = newSpoolTxBlock(builder, borrowIncentiveTxBlock);
|
|
3461
3970
|
const coreTxBlock = newCoreTxBlock(builder, spoolTxBlock);
|
|
3462
3971
|
return new Proxy(coreTxBlock, {
|
|
3463
3972
|
get: (target, prop) => {
|
|
3464
|
-
if (prop in
|
|
3973
|
+
if (prop in borrowIncentiveTxBlock) {
|
|
3974
|
+
return Reflect.get(borrowIncentiveTxBlock, prop);
|
|
3975
|
+
} else if (prop in spoolTxBlock) {
|
|
3465
3976
|
return Reflect.get(spoolTxBlock, prop);
|
|
3466
3977
|
}
|
|
3467
3978
|
return Reflect.get(target, prop);
|
|
@@ -3473,7 +3984,7 @@ var newScallopTxBlock = (builder, initTxBlock) => {
|
|
|
3473
3984
|
var ScallopBuilder = class {
|
|
3474
3985
|
constructor(params, instance) {
|
|
3475
3986
|
this.params = params;
|
|
3476
|
-
this.suiKit = instance?.suiKit ?? new
|
|
3987
|
+
this.suiKit = instance?.suiKit ?? new import_sui_kit8.SuiKit(params);
|
|
3477
3988
|
this.address = instance?.address ?? new ScallopAddress({
|
|
3478
3989
|
id: params?.addressesId || ADDRESSES_ID,
|
|
3479
3990
|
network: params?.networkType
|
|
@@ -3487,7 +3998,7 @@ var ScallopBuilder = class {
|
|
|
3487
3998
|
address: this.address,
|
|
3488
3999
|
query: this.query
|
|
3489
4000
|
});
|
|
3490
|
-
this.walletAddress = (0,
|
|
4001
|
+
this.walletAddress = (0, import_utils18.normalizeSuiAddress)(
|
|
3491
4002
|
params?.walletAddress || this.suiKit.currentAddress()
|
|
3492
4003
|
);
|
|
3493
4004
|
this.isTestnet = params.networkType ? params.networkType === "testnet" : false;
|
|
@@ -3563,7 +4074,7 @@ var ScallopBuilder = class {
|
|
|
3563
4074
|
var ScallopClient = class {
|
|
3564
4075
|
constructor(params, instance) {
|
|
3565
4076
|
this.params = params;
|
|
3566
|
-
this.suiKit = instance?.suiKit ?? new
|
|
4077
|
+
this.suiKit = instance?.suiKit ?? new import_sui_kit9.SuiKit(params);
|
|
3567
4078
|
this.address = instance?.address ?? new ScallopAddress({
|
|
3568
4079
|
id: params?.addressesId || ADDRESSES_ID,
|
|
3569
4080
|
network: params?.networkType
|
|
@@ -3583,7 +4094,7 @@ var ScallopClient = class {
|
|
|
3583
4094
|
query: this.query,
|
|
3584
4095
|
utils: this.utils
|
|
3585
4096
|
});
|
|
3586
|
-
this.walletAddress = (0,
|
|
4097
|
+
this.walletAddress = (0, import_utils19.normalizeSuiAddress)(
|
|
3587
4098
|
params?.walletAddress || this.suiKit.currentAddress()
|
|
3588
4099
|
);
|
|
3589
4100
|
}
|
|
@@ -3685,8 +4196,8 @@ var ScallopClient = class {
|
|
|
3685
4196
|
* @param stakeMarketCoinName - Support stake market coin.
|
|
3686
4197
|
* @return Reward pool data.
|
|
3687
4198
|
*/
|
|
3688
|
-
async
|
|
3689
|
-
return await this.query.
|
|
4199
|
+
async getStakeRewardPool(stakeMarketCoinName) {
|
|
4200
|
+
return await this.query.getStakeRewardPool(stakeMarketCoinName);
|
|
3690
4201
|
}
|
|
3691
4202
|
async openObligation(sign = true) {
|
|
3692
4203
|
const txBlock = this.builder.createTxBlock();
|
|
@@ -3958,11 +4469,84 @@ var ScallopClient = class {
|
|
|
3958
4469
|
const txBlock = this.builder.createTxBlock();
|
|
3959
4470
|
const sender = walletAddress || this.walletAddress;
|
|
3960
4471
|
txBlock.setSender(sender);
|
|
3961
|
-
const
|
|
4472
|
+
const rewardCoins = await txBlock.claimQuick(
|
|
3962
4473
|
stakeMarketCoinName,
|
|
3963
4474
|
stakeAccountId
|
|
3964
4475
|
);
|
|
3965
|
-
txBlock.transferObjects(
|
|
4476
|
+
txBlock.transferObjects(rewardCoins, sender);
|
|
4477
|
+
if (sign) {
|
|
4478
|
+
return await this.suiKit.signAndSendTxn(
|
|
4479
|
+
txBlock
|
|
4480
|
+
);
|
|
4481
|
+
} else {
|
|
4482
|
+
return txBlock.txBlock;
|
|
4483
|
+
}
|
|
4484
|
+
}
|
|
4485
|
+
/* ==================== Borrow Incentive Method ==================== */
|
|
4486
|
+
/**
|
|
4487
|
+
* stake obligaion.
|
|
4488
|
+
*
|
|
4489
|
+
* @param sign - Decide to directly sign the transaction or return the transaction block.
|
|
4490
|
+
* @param obligaionId - The obligation account object.
|
|
4491
|
+
* @param obligaionKeyId - The obligation key account object.
|
|
4492
|
+
* @param walletAddress - The wallet address of the owner.
|
|
4493
|
+
* @return Transaction block response or transaction block
|
|
4494
|
+
*/
|
|
4495
|
+
async stakeObligation(coinName, obligaionId, obligaionKeyId, sign = true, walletAddress) {
|
|
4496
|
+
const txBlock = this.builder.createTxBlock();
|
|
4497
|
+
const sender = walletAddress || this.walletAddress;
|
|
4498
|
+
txBlock.setSender(sender);
|
|
4499
|
+
await txBlock.stakeObligationQuick(coinName, obligaionId, obligaionKeyId);
|
|
4500
|
+
if (sign) {
|
|
4501
|
+
return await this.suiKit.signAndSendTxn(
|
|
4502
|
+
txBlock
|
|
4503
|
+
);
|
|
4504
|
+
} else {
|
|
4505
|
+
return txBlock.txBlock;
|
|
4506
|
+
}
|
|
4507
|
+
}
|
|
4508
|
+
/**
|
|
4509
|
+
* unstake obligaion.
|
|
4510
|
+
*
|
|
4511
|
+
* @param sign - Decide to directly sign the transaction or return the transaction block.
|
|
4512
|
+
* @param obligaionId - The obligation account object.
|
|
4513
|
+
* @param obligaionKeyId - The obligation key account object.
|
|
4514
|
+
* @param walletAddress - The wallet address of the owner.
|
|
4515
|
+
* @return Transaction block response or transaction block
|
|
4516
|
+
*/
|
|
4517
|
+
async unstakeObligation(coinName, obligaionId, obligaionKeyId, sign = true, walletAddress) {
|
|
4518
|
+
const txBlock = this.builder.createTxBlock();
|
|
4519
|
+
const sender = walletAddress || this.walletAddress;
|
|
4520
|
+
txBlock.setSender(sender);
|
|
4521
|
+
await txBlock.unstakeObligationQuick(coinName, obligaionId, obligaionKeyId);
|
|
4522
|
+
if (sign) {
|
|
4523
|
+
return await this.suiKit.signAndSendTxn(
|
|
4524
|
+
txBlock
|
|
4525
|
+
);
|
|
4526
|
+
} else {
|
|
4527
|
+
return txBlock.txBlock;
|
|
4528
|
+
}
|
|
4529
|
+
}
|
|
4530
|
+
/**
|
|
4531
|
+
* unstake market coin from the specific spool.
|
|
4532
|
+
*
|
|
4533
|
+
* @param marketCoinName - Types of mak coin.
|
|
4534
|
+
* @param amount - The amount of coins would deposit.
|
|
4535
|
+
* @param sign - Decide to directly sign the transaction or return the transaction block.
|
|
4536
|
+
* @param accountId - The stake account object.
|
|
4537
|
+
* @param walletAddress - The wallet address of the owner.
|
|
4538
|
+
* @return Transaction block response or transaction block
|
|
4539
|
+
*/
|
|
4540
|
+
async claimBorrowIncentive(coinName, obligaionId, obligaionKeyId, sign = true, walletAddress) {
|
|
4541
|
+
const txBlock = this.builder.createTxBlock();
|
|
4542
|
+
const sender = walletAddress || this.walletAddress;
|
|
4543
|
+
txBlock.setSender(sender);
|
|
4544
|
+
const rewardCoin = await txBlock.claimBorrowIncentiveQuick(
|
|
4545
|
+
coinName,
|
|
4546
|
+
obligaionId,
|
|
4547
|
+
obligaionKeyId
|
|
4548
|
+
);
|
|
4549
|
+
txBlock.transferObjects([rewardCoin], sender);
|
|
3966
4550
|
if (sign) {
|
|
3967
4551
|
return await this.suiKit.signAndSendTxn(
|
|
3968
4552
|
txBlock
|
|
@@ -3997,7 +4581,7 @@ var ScallopClient = class {
|
|
|
3997
4581
|
var Scallop = class {
|
|
3998
4582
|
constructor(params) {
|
|
3999
4583
|
this.params = params;
|
|
4000
|
-
this.suiKit = new
|
|
4584
|
+
this.suiKit = new import_sui_kit10.SuiKit(params);
|
|
4001
4585
|
this._address = new ScallopAddress({
|
|
4002
4586
|
id: params?.addressesId || ADDRESSES_ID,
|
|
4003
4587
|
network: params?.networkType
|
|
@@ -4076,12 +4660,14 @@ var Scallop = class {
|
|
|
4076
4660
|
ADDRESSES_ID,
|
|
4077
4661
|
API_BASE_URL,
|
|
4078
4662
|
PROTOCOL_OBJECT_ID,
|
|
4663
|
+
SUPPORT_BORROW_INCENTIVE_POOLS,
|
|
4664
|
+
SUPPORT_BORROW_INCENTIVE_REWARDS,
|
|
4079
4665
|
SUPPORT_COLLATERALS,
|
|
4080
4666
|
SUPPORT_ORACLES,
|
|
4081
4667
|
SUPPORT_PACKAGES,
|
|
4082
4668
|
SUPPORT_POOLS,
|
|
4083
|
-
SUPPORT_REWARD_POOLS,
|
|
4084
4669
|
SUPPORT_SPOOLS,
|
|
4670
|
+
SUPPORT_SPOOLS_REWARDS,
|
|
4085
4671
|
Scallop,
|
|
4086
4672
|
ScallopAddress,
|
|
4087
4673
|
ScallopBuilder,
|
|
@@ -4089,10 +4675,11 @@ var Scallop = class {
|
|
|
4089
4675
|
ScallopQuery,
|
|
4090
4676
|
ScallopUtils,
|
|
4091
4677
|
assetCoins,
|
|
4678
|
+
borrowIncentiveRewardCoins,
|
|
4092
4679
|
coinDecimals,
|
|
4093
4680
|
coinIds,
|
|
4094
4681
|
marketCoins,
|
|
4095
|
-
|
|
4682
|
+
spoolRewardCoins,
|
|
4096
4683
|
stakeMarketCoins,
|
|
4097
4684
|
voloCoinIds,
|
|
4098
4685
|
wormholeCoinIds
|