@scallop-io/sui-scallop-sdk 0.44.2 → 0.44.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/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 +753 -211
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +714 -175
- 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/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 +166 -0
- package/src/queries/coreQuery.ts +57 -15
- package/src/queries/index.ts +1 -0
- package/src/queries/spoolQuery.ts +78 -62
- 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/spool.ts +28 -18
- package/src/utils/builder.ts +15 -0
- package/src/utils/index.ts +1 -1
- package/src/utils/query.ts +277 -70
- 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,43 +705,33 @@ var ScallopAddress = class {
|
|
|
688
705
|
};
|
|
689
706
|
|
|
690
707
|
// src/models/scallopClient.ts
|
|
691
|
-
var
|
|
692
|
-
var
|
|
708
|
+
var import_utils17 = 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_utils7 = 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
|
|
703
720
|
var import_sui_kit = require("@scallop-io/sui-kit");
|
|
704
721
|
var import_bignumber2 = __toESM(require("bignumber.js"));
|
|
705
722
|
|
|
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");
|
|
723
|
+
// src/utils/builder.ts
|
|
724
|
+
var requireSender = (txBlock) => {
|
|
725
|
+
const sender = txBlock.blockData.sender;
|
|
726
|
+
if (!sender) {
|
|
727
|
+
throw new Error("Sender is required");
|
|
723
728
|
}
|
|
729
|
+
return sender;
|
|
724
730
|
};
|
|
725
731
|
|
|
726
732
|
// src/utils/query.ts
|
|
727
733
|
var import_bignumber = __toESM(require("bignumber.js"));
|
|
734
|
+
var import_utils = require("@mysten/sui.js/utils");
|
|
728
735
|
var parseOriginMarketPoolData = (originMarketPoolData) => {
|
|
729
736
|
return {
|
|
730
737
|
coinType: "0x" + originMarketPoolData.type.name,
|
|
@@ -851,48 +858,48 @@ var calculateMarketCollateralData = (utils, parsedMarketCollateralData) => {
|
|
|
851
858
|
depositCoin: depositCoin.toNumber()
|
|
852
859
|
};
|
|
853
860
|
};
|
|
854
|
-
var
|
|
861
|
+
var parseOriginSpoolData = (originSpoolData) => {
|
|
855
862
|
return {
|
|
856
|
-
stakeType: "0x" +
|
|
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(
|
|
863
|
+
stakeType: "0x" + originSpoolData.stakeType.fields.name,
|
|
864
|
+
maxPoint: Number(originSpoolData.maxDistributedPoint),
|
|
865
|
+
distributedPoint: Number(originSpoolData.distributedPoint),
|
|
866
|
+
pointPerPeriod: Number(originSpoolData.distributedPointPerPeriod),
|
|
867
|
+
period: Number(originSpoolData.pointDistributionTime),
|
|
868
|
+
maxStake: Number(originSpoolData.maxStake),
|
|
869
|
+
staked: Number(originSpoolData.stakes),
|
|
870
|
+
index: Number(originSpoolData.index),
|
|
871
|
+
createdAt: Number(originSpoolData.createdAt),
|
|
872
|
+
lastUpdate: Number(originSpoolData.lastUpdate)
|
|
866
873
|
};
|
|
867
874
|
};
|
|
868
|
-
var
|
|
875
|
+
var calculateSpoolData = (parsedSpoolData, stakeMarketCoinPrice, stakeMarketCoinDecimal) => {
|
|
869
876
|
const baseIndexRate = 1e9;
|
|
870
877
|
const distributedPointPerSec = (0, import_bignumber.default)(
|
|
871
|
-
|
|
872
|
-
).dividedBy(
|
|
873
|
-
const pointPerSec = (0, import_bignumber.default)(
|
|
874
|
-
|
|
878
|
+
parsedSpoolData.pointPerPeriod
|
|
879
|
+
).dividedBy(parsedSpoolData.period);
|
|
880
|
+
const pointPerSec = (0, import_bignumber.default)(parsedSpoolData.pointPerPeriod).dividedBy(
|
|
881
|
+
parsedSpoolData.period
|
|
875
882
|
);
|
|
876
|
-
const remainingPeriod = (0, import_bignumber.default)(
|
|
877
|
-
const startDate =
|
|
878
|
-
const endDate = remainingPeriod.plus(
|
|
883
|
+
const remainingPeriod = (0, import_bignumber.default)(parsedSpoolData.maxPoint).minus(parsedSpoolData.distributedPoint).dividedBy(pointPerSec);
|
|
884
|
+
const startDate = parsedSpoolData.createdAt;
|
|
885
|
+
const endDate = remainingPeriod.plus(parsedSpoolData.lastUpdate).integerValue().toNumber();
|
|
879
886
|
const timeDelta = (0, import_bignumber.default)(
|
|
880
|
-
Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) -
|
|
881
|
-
).dividedBy(
|
|
882
|
-
const remainingPoints = (0, import_bignumber.default)(
|
|
883
|
-
|
|
887
|
+
Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) - parsedSpoolData.lastUpdate
|
|
888
|
+
).dividedBy(parsedSpoolData.period).toFixed(0);
|
|
889
|
+
const remainingPoints = (0, import_bignumber.default)(parsedSpoolData.maxPoint).minus(
|
|
890
|
+
parsedSpoolData.distributedPoint
|
|
884
891
|
);
|
|
885
892
|
const accumulatedPoints = import_bignumber.default.minimum(
|
|
886
|
-
(0, import_bignumber.default)(timeDelta).multipliedBy(
|
|
893
|
+
(0, import_bignumber.default)(timeDelta).multipliedBy(parsedSpoolData.pointPerPeriod),
|
|
887
894
|
remainingPoints
|
|
888
895
|
);
|
|
889
|
-
const currentPointIndex = (0, import_bignumber.default)(
|
|
890
|
-
accumulatedPoints.dividedBy(
|
|
896
|
+
const currentPointIndex = (0, import_bignumber.default)(parsedSpoolData.index).plus(
|
|
897
|
+
accumulatedPoints.dividedBy(parsedSpoolData.staked).isFinite() ? (0, import_bignumber.default)(baseIndexRate).multipliedBy(accumulatedPoints).dividedBy(parsedSpoolData.staked) : 0
|
|
891
898
|
);
|
|
892
899
|
const currentTotalDistributedPoint = (0, import_bignumber.default)(
|
|
893
|
-
|
|
900
|
+
parsedSpoolData.distributedPoint
|
|
894
901
|
).plus(accumulatedPoints);
|
|
895
|
-
const stakedAmount = (0, import_bignumber.default)(
|
|
902
|
+
const stakedAmount = (0, import_bignumber.default)(parsedSpoolData.staked);
|
|
896
903
|
const stakedCoin = stakedAmount.shiftedBy(-1 * stakeMarketCoinDecimal);
|
|
897
904
|
const stakedValue = stakedCoin.multipliedBy(stakeMarketCoinPrice);
|
|
898
905
|
return {
|
|
@@ -907,35 +914,39 @@ var calculateStakePoolData = (parsedStakePoolData, stakeMarketCoinPrice, stakeMa
|
|
|
907
914
|
stakedValue: stakedValue.toNumber()
|
|
908
915
|
};
|
|
909
916
|
};
|
|
910
|
-
var
|
|
917
|
+
var parseOriginSpoolRewardPoolData = (originSpoolRewardPoolData) => {
|
|
911
918
|
return {
|
|
912
|
-
claimedRewards: Number(
|
|
913
|
-
exchangeRateNumerator: Number(
|
|
919
|
+
claimedRewards: Number(originSpoolRewardPoolData.claimed_rewards),
|
|
920
|
+
exchangeRateNumerator: Number(
|
|
921
|
+
originSpoolRewardPoolData.exchange_rate_numerator
|
|
922
|
+
),
|
|
914
923
|
exchangeRateDenominator: Number(
|
|
915
|
-
|
|
924
|
+
originSpoolRewardPoolData.exchange_rate_denominator
|
|
916
925
|
),
|
|
917
|
-
rewards: Number(
|
|
918
|
-
spoolId: String(
|
|
926
|
+
rewards: Number(originSpoolRewardPoolData.rewards),
|
|
927
|
+
spoolId: String(originSpoolRewardPoolData.spool_id)
|
|
919
928
|
};
|
|
920
929
|
};
|
|
921
|
-
var
|
|
930
|
+
var calculateSpoolRewardPoolData = (parsedSpoolData, parsedSpoolRewardPoolData, calculatedSpoolData, rewardCoinPrice, rewardCoinDecimal) => {
|
|
922
931
|
const rateYearFactor = 365 * 24 * 60 * 60;
|
|
923
|
-
const rewardPerSec = (0, import_bignumber.default)(
|
|
924
|
-
const totalRewardAmount = (0, import_bignumber.default)(
|
|
932
|
+
const rewardPerSec = (0, import_bignumber.default)(calculatedSpoolData.distributedPointPerSec).multipliedBy(parsedSpoolRewardPoolData.exchangeRateNumerator).dividedBy(parsedSpoolRewardPoolData.exchangeRateDenominator);
|
|
933
|
+
const totalRewardAmount = (0, import_bignumber.default)(parsedSpoolData.maxPoint).multipliedBy(parsedSpoolRewardPoolData.exchangeRateNumerator).dividedBy(parsedSpoolRewardPoolData.exchangeRateDenominator);
|
|
925
934
|
const totalRewardCoin = totalRewardAmount.shiftedBy(-1 * rewardCoinDecimal);
|
|
926
935
|
const totalRewardValue = totalRewardCoin.multipliedBy(rewardCoinPrice);
|
|
927
|
-
const remaindRewardAmount = (0, import_bignumber.default)(
|
|
936
|
+
const remaindRewardAmount = (0, import_bignumber.default)(parsedSpoolRewardPoolData.rewards);
|
|
928
937
|
const remaindRewardCoin = remaindRewardAmount.shiftedBy(
|
|
929
938
|
-1 * rewardCoinDecimal
|
|
930
939
|
);
|
|
931
940
|
const remaindRewardValue = remaindRewardCoin.multipliedBy(rewardCoinPrice);
|
|
932
|
-
const claimedRewardAmount = (0, import_bignumber.default)(
|
|
941
|
+
const claimedRewardAmount = (0, import_bignumber.default)(
|
|
942
|
+
parsedSpoolRewardPoolData.claimedRewards
|
|
943
|
+
);
|
|
933
944
|
const claimedRewardCoin = claimedRewardAmount.shiftedBy(
|
|
934
945
|
-1 * rewardCoinDecimal
|
|
935
946
|
);
|
|
936
947
|
const claimedRewardValue = claimedRewardCoin.multipliedBy(rewardCoinPrice);
|
|
937
948
|
const rewardValueForYear = (0, import_bignumber.default)(rewardPerSec).shiftedBy(-1 * rewardCoinDecimal).multipliedBy(rateYearFactor).multipliedBy(rewardCoinPrice);
|
|
938
|
-
const rewardRate = rewardValueForYear.dividedBy(
|
|
949
|
+
const rewardRate = rewardValueForYear.dividedBy(calculatedSpoolData.stakedValue).isFinite() ? rewardValueForYear.dividedBy(calculatedSpoolData.stakedValue).toNumber() : Infinity;
|
|
939
950
|
return {
|
|
940
951
|
rewardApr: rewardRate,
|
|
941
952
|
totalRewardAmount: totalRewardAmount.toNumber(),
|
|
@@ -947,9 +958,133 @@ var calculateRewardPoolData = (parsedStakePoolData, parsedRewardPoolData, calcul
|
|
|
947
958
|
claimedRewardAmount: claimedRewardAmount.toNumber(),
|
|
948
959
|
claimedRewardCoin: claimedRewardCoin.toNumber(),
|
|
949
960
|
claimedRewardValue: claimedRewardValue.toNumber(),
|
|
950
|
-
rewardPerSec: rewardPerSec.toNumber()
|
|
951
|
-
|
|
952
|
-
|
|
961
|
+
rewardPerSec: rewardPerSec.toNumber()
|
|
962
|
+
};
|
|
963
|
+
};
|
|
964
|
+
var parseOriginBorrowIncentivePoolData = (originBorrowIncentivePoolData) => {
|
|
965
|
+
return {
|
|
966
|
+
poolType: (0, import_utils.normalizeStructTag)(originBorrowIncentivePoolData.pool_type.name),
|
|
967
|
+
maxPoint: Number(originBorrowIncentivePoolData.max_distributed_point),
|
|
968
|
+
distributedPoint: Number(originBorrowIncentivePoolData.distributed_point),
|
|
969
|
+
pointPerPeriod: Number(
|
|
970
|
+
originBorrowIncentivePoolData.distributed_point_per_period
|
|
971
|
+
),
|
|
972
|
+
period: Number(originBorrowIncentivePoolData.point_distribution_time),
|
|
973
|
+
maxStake: Number(originBorrowIncentivePoolData.max_stakes),
|
|
974
|
+
staked: Number(originBorrowIncentivePoolData.stakes),
|
|
975
|
+
index: Number(originBorrowIncentivePoolData.index),
|
|
976
|
+
createdAt: Number(originBorrowIncentivePoolData.created_at),
|
|
977
|
+
lastUpdate: Number(originBorrowIncentivePoolData.last_update)
|
|
978
|
+
};
|
|
979
|
+
};
|
|
980
|
+
var calculateBorrowIncentivePoolData = (parsedBorrowIncentivePoolData, borrowIncentiveCoinPrice, borrowIncentiveCoinDecimal) => {
|
|
981
|
+
const baseIndexRate = 1e9;
|
|
982
|
+
const distributedPointPerSec = (0, import_bignumber.default)(
|
|
983
|
+
parsedBorrowIncentivePoolData.pointPerPeriod
|
|
984
|
+
).dividedBy(parsedBorrowIncentivePoolData.period);
|
|
985
|
+
const pointPerSec = (0, import_bignumber.default)(
|
|
986
|
+
parsedBorrowIncentivePoolData.pointPerPeriod
|
|
987
|
+
).dividedBy(parsedBorrowIncentivePoolData.period);
|
|
988
|
+
const remainingPeriod = (0, import_bignumber.default)(parsedBorrowIncentivePoolData.maxPoint).minus(parsedBorrowIncentivePoolData.distributedPoint).dividedBy(pointPerSec);
|
|
989
|
+
const startDate = parsedBorrowIncentivePoolData.createdAt;
|
|
990
|
+
const endDate = remainingPeriod.plus(parsedBorrowIncentivePoolData.lastUpdate).integerValue().toNumber();
|
|
991
|
+
const timeDelta = (0, import_bignumber.default)(
|
|
992
|
+
Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) - parsedBorrowIncentivePoolData.lastUpdate
|
|
993
|
+
).dividedBy(parsedBorrowIncentivePoolData.period).toFixed(0);
|
|
994
|
+
const remainingPoints = (0, import_bignumber.default)(
|
|
995
|
+
parsedBorrowIncentivePoolData.maxPoint
|
|
996
|
+
).minus(parsedBorrowIncentivePoolData.distributedPoint);
|
|
997
|
+
const accumulatedPoints = import_bignumber.default.minimum(
|
|
998
|
+
(0, import_bignumber.default)(timeDelta).multipliedBy(
|
|
999
|
+
parsedBorrowIncentivePoolData.pointPerPeriod
|
|
1000
|
+
),
|
|
1001
|
+
remainingPoints
|
|
1002
|
+
);
|
|
1003
|
+
const currentPointIndex = (0, import_bignumber.default)(parsedBorrowIncentivePoolData.index).plus(
|
|
1004
|
+
accumulatedPoints.dividedBy(parsedBorrowIncentivePoolData.staked).isFinite() ? (0, import_bignumber.default)(baseIndexRate).multipliedBy(accumulatedPoints).dividedBy(parsedBorrowIncentivePoolData.staked) : 0
|
|
1005
|
+
);
|
|
1006
|
+
const currentTotalDistributedPoint = (0, import_bignumber.default)(
|
|
1007
|
+
parsedBorrowIncentivePoolData.distributedPoint
|
|
1008
|
+
).plus(accumulatedPoints);
|
|
1009
|
+
const stakedAmount = (0, import_bignumber.default)(parsedBorrowIncentivePoolData.staked);
|
|
1010
|
+
const stakedCoin = stakedAmount.shiftedBy(-1 * borrowIncentiveCoinDecimal);
|
|
1011
|
+
const stakedValue = stakedCoin.multipliedBy(borrowIncentiveCoinPrice);
|
|
1012
|
+
return {
|
|
1013
|
+
distributedPointPerSec: distributedPointPerSec.toNumber(),
|
|
1014
|
+
accumulatedPoints: accumulatedPoints.toNumber(),
|
|
1015
|
+
currentPointIndex: currentPointIndex.toNumber(),
|
|
1016
|
+
currentTotalDistributedPoint: currentTotalDistributedPoint.toNumber(),
|
|
1017
|
+
startDate: new Date(startDate * 1e3),
|
|
1018
|
+
endDate: new Date(endDate * 1e3),
|
|
1019
|
+
stakedAmount: stakedAmount.toNumber(),
|
|
1020
|
+
stakedCoin: stakedCoin.toNumber(),
|
|
1021
|
+
stakedValue: stakedValue.toNumber()
|
|
1022
|
+
};
|
|
1023
|
+
};
|
|
1024
|
+
var parseOriginBorrowIncentiveRewardPoolData = (originBorrowIncentiveRewardPoolData) => {
|
|
1025
|
+
return {
|
|
1026
|
+
rewardType: (0, import_utils.normalizeStructTag)(
|
|
1027
|
+
originBorrowIncentiveRewardPoolData.reward_type.name
|
|
1028
|
+
),
|
|
1029
|
+
claimedRewards: Number(originBorrowIncentiveRewardPoolData.claimed_rewards),
|
|
1030
|
+
exchangeRateNumerator: Number(
|
|
1031
|
+
originBorrowIncentiveRewardPoolData.exchange_rate_numerator
|
|
1032
|
+
),
|
|
1033
|
+
exchangeRateDenominator: Number(
|
|
1034
|
+
originBorrowIncentiveRewardPoolData.exchange_rate_denominator
|
|
1035
|
+
),
|
|
1036
|
+
remainingRewards: Number(
|
|
1037
|
+
originBorrowIncentiveRewardPoolData.remaining_reward
|
|
1038
|
+
)
|
|
1039
|
+
};
|
|
1040
|
+
};
|
|
1041
|
+
var calculateBorrowIncentiveRewardPoolData = (parsedBorrowIncentivePoolData, parsedBorrowIncentiveRewardPoolData, calculatedBorrowIncentivePoolData, rewardCoinPrice, rewardCoinDecimal) => {
|
|
1042
|
+
const rateYearFactor = 365 * 24 * 60 * 60;
|
|
1043
|
+
const rewardPerSec = (0, import_bignumber.default)(
|
|
1044
|
+
calculatedBorrowIncentivePoolData.distributedPointPerSec
|
|
1045
|
+
).multipliedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateNumerator).dividedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateDenominator);
|
|
1046
|
+
const totalRewardAmount = (0, import_bignumber.default)(parsedBorrowIncentivePoolData.maxPoint).multipliedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateNumerator).dividedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateDenominator);
|
|
1047
|
+
const totalRewardCoin = totalRewardAmount.shiftedBy(-1 * rewardCoinDecimal);
|
|
1048
|
+
const totalRewardValue = totalRewardCoin.multipliedBy(rewardCoinPrice);
|
|
1049
|
+
const remaindRewardAmount = (0, import_bignumber.default)(
|
|
1050
|
+
parsedBorrowIncentiveRewardPoolData.remainingRewards
|
|
1051
|
+
);
|
|
1052
|
+
const remaindRewardCoin = remaindRewardAmount.shiftedBy(
|
|
1053
|
+
-1 * rewardCoinDecimal
|
|
1054
|
+
);
|
|
1055
|
+
const remaindRewardValue = remaindRewardCoin.multipliedBy(rewardCoinPrice);
|
|
1056
|
+
const claimedRewardAmount = (0, import_bignumber.default)(
|
|
1057
|
+
parsedBorrowIncentiveRewardPoolData.claimedRewards
|
|
1058
|
+
);
|
|
1059
|
+
const claimedRewardCoin = claimedRewardAmount.shiftedBy(
|
|
1060
|
+
-1 * rewardCoinDecimal
|
|
1061
|
+
);
|
|
1062
|
+
const claimedRewardValue = claimedRewardCoin.multipliedBy(rewardCoinPrice);
|
|
1063
|
+
const rewardValueForYear = (0, import_bignumber.default)(rewardPerSec).shiftedBy(-1 * rewardCoinDecimal).multipliedBy(rateYearFactor).multipliedBy(rewardCoinPrice);
|
|
1064
|
+
const rewardRate = rewardValueForYear.dividedBy(calculatedBorrowIncentivePoolData.stakedValue).isFinite() ? rewardValueForYear.dividedBy(calculatedBorrowIncentivePoolData.stakedValue).toNumber() : Infinity;
|
|
1065
|
+
return {
|
|
1066
|
+
rewardApr: rewardRate,
|
|
1067
|
+
totalRewardAmount: totalRewardAmount.toNumber(),
|
|
1068
|
+
totalRewardCoin: totalRewardCoin.toNumber(),
|
|
1069
|
+
totalRewardValue: totalRewardValue.toNumber(),
|
|
1070
|
+
remaindRewardAmount: remaindRewardAmount.toNumber(),
|
|
1071
|
+
remaindRewardCoin: remaindRewardCoin.toNumber(),
|
|
1072
|
+
remaindRewardValue: remaindRewardValue.toNumber(),
|
|
1073
|
+
claimedRewardAmount: claimedRewardAmount.toNumber(),
|
|
1074
|
+
claimedRewardCoin: claimedRewardCoin.toNumber(),
|
|
1075
|
+
claimedRewardValue: claimedRewardValue.toNumber(),
|
|
1076
|
+
rewardPerSec: rewardPerSec.toNumber()
|
|
1077
|
+
};
|
|
1078
|
+
};
|
|
1079
|
+
var parseOriginBorrowIncentiveAccountData = (originBorrowIncentiveAccountData) => {
|
|
1080
|
+
return {
|
|
1081
|
+
poolType: (0, import_utils.normalizeStructTag)(
|
|
1082
|
+
originBorrowIncentiveAccountData.pool_type.name
|
|
1083
|
+
),
|
|
1084
|
+
amount: Number(originBorrowIncentiveAccountData.amount),
|
|
1085
|
+
index: Number(originBorrowIncentiveAccountData.index),
|
|
1086
|
+
points: Number(originBorrowIncentiveAccountData.points),
|
|
1087
|
+
totalPoints: Number(originBorrowIncentiveAccountData.total_points)
|
|
953
1088
|
};
|
|
954
1089
|
};
|
|
955
1090
|
var minBigNumber = (...args) => {
|
|
@@ -967,7 +1102,7 @@ var isMarketCoin = (coinName) => {
|
|
|
967
1102
|
.../* @__PURE__ */ new Set([
|
|
968
1103
|
...SUPPORT_POOLS,
|
|
969
1104
|
...SUPPORT_COLLATERALS,
|
|
970
|
-
...
|
|
1105
|
+
...SUPPORT_SPOOLS_REWARDS
|
|
971
1106
|
])
|
|
972
1107
|
].includes(assetCoinName);
|
|
973
1108
|
};
|
|
@@ -983,6 +1118,24 @@ var parseAssetSymbol = (coinName) => {
|
|
|
983
1118
|
return coinName.toUpperCase();
|
|
984
1119
|
}
|
|
985
1120
|
};
|
|
1121
|
+
var parseDataFromPythPriceFeed = (feed, address) => {
|
|
1122
|
+
const assetCoinNames = [
|
|
1123
|
+
.../* @__PURE__ */ new Set([...SUPPORT_POOLS, ...SUPPORT_COLLATERALS])
|
|
1124
|
+
];
|
|
1125
|
+
const assetCoinName = assetCoinNames.find((assetCoinName2) => {
|
|
1126
|
+
return address.get(`core.coins.${assetCoinName2}.oracle.pyth.feed`) === feed.id;
|
|
1127
|
+
});
|
|
1128
|
+
if (assetCoinName) {
|
|
1129
|
+
const price = feed.price.price * 10 ** feed.price.expo;
|
|
1130
|
+
return {
|
|
1131
|
+
coinName: assetCoinName,
|
|
1132
|
+
price,
|
|
1133
|
+
publishTime: Number(feed.price.publishTime) * 10 ** 3
|
|
1134
|
+
};
|
|
1135
|
+
} else {
|
|
1136
|
+
throw new Error("Invalid feed id");
|
|
1137
|
+
}
|
|
1138
|
+
};
|
|
986
1139
|
|
|
987
1140
|
// src/queries/coreQuery.ts
|
|
988
1141
|
var queryMarket = async (query) => {
|
|
@@ -996,6 +1149,12 @@ var queryMarket = async (query) => {
|
|
|
996
1149
|
const pools = {};
|
|
997
1150
|
const collaterals = {};
|
|
998
1151
|
for (const pool of marketData.pools) {
|
|
1152
|
+
const coinType = "0x" + pool.type.name;
|
|
1153
|
+
const poolCoinName = query.utils.parseCoinNameFromType(coinType);
|
|
1154
|
+
const coinPrice = (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName] ?? 0;
|
|
1155
|
+
if (!SUPPORT_POOLS.includes(poolCoinName)) {
|
|
1156
|
+
continue;
|
|
1157
|
+
}
|
|
999
1158
|
const parsedMarketPoolData = parseOriginMarketPoolData({
|
|
1000
1159
|
type: pool.type,
|
|
1001
1160
|
maxBorrowRate: pool.maxBorrowRate,
|
|
@@ -1020,9 +1179,6 @@ var queryMarket = async (query) => {
|
|
|
1020
1179
|
query.utils,
|
|
1021
1180
|
parsedMarketPoolData
|
|
1022
1181
|
);
|
|
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
1182
|
pools[poolCoinName] = {
|
|
1027
1183
|
coinName: poolCoinName,
|
|
1028
1184
|
symbol: query.utils.parseSymbol(poolCoinName),
|
|
@@ -1041,6 +1197,12 @@ var queryMarket = async (query) => {
|
|
|
1041
1197
|
};
|
|
1042
1198
|
}
|
|
1043
1199
|
for (const collateral of marketData.collaterals) {
|
|
1200
|
+
const coinType = "0x" + collateral.type.name;
|
|
1201
|
+
const collateralCoinName = query.utils.parseCoinNameFromType(coinType);
|
|
1202
|
+
const coinPrice = (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName] ?? 0;
|
|
1203
|
+
if (!SUPPORT_COLLATERALS.includes(collateralCoinName)) {
|
|
1204
|
+
continue;
|
|
1205
|
+
}
|
|
1044
1206
|
const parsedMarketCollateralData = parseOriginMarketCollateralData({
|
|
1045
1207
|
type: collateral.type,
|
|
1046
1208
|
collateralFactor: collateral.collateralFactor,
|
|
@@ -1055,9 +1217,6 @@ var queryMarket = async (query) => {
|
|
|
1055
1217
|
query.utils,
|
|
1056
1218
|
parsedMarketCollateralData
|
|
1057
1219
|
);
|
|
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
1220
|
collaterals[collateralCoinName] = {
|
|
1062
1221
|
coinName: collateralCoinName,
|
|
1063
1222
|
symbol: query.utils.parseSymbol(collateralCoinName),
|
|
@@ -1344,11 +1503,27 @@ var getObligations = async (query, ownerAddress) => {
|
|
|
1344
1503
|
if (keyObject.content && "fields" in keyObject.content) {
|
|
1345
1504
|
const fields = keyObject.content.fields;
|
|
1346
1505
|
const obligationId = String(fields.ownership.fields.of);
|
|
1347
|
-
|
|
1506
|
+
const locked = await getObligationLocked(query, obligationId);
|
|
1507
|
+
obligations.push({ id: obligationId, keyId, locked });
|
|
1348
1508
|
}
|
|
1349
1509
|
}
|
|
1350
1510
|
return obligations;
|
|
1351
1511
|
};
|
|
1512
|
+
var getObligationLocked = async (query, obligationId) => {
|
|
1513
|
+
const obligationObjectResponse = await query.suiKit.client().getObject({
|
|
1514
|
+
id: obligationId,
|
|
1515
|
+
options: {
|
|
1516
|
+
showContent: true
|
|
1517
|
+
}
|
|
1518
|
+
});
|
|
1519
|
+
let obligationLocked = false;
|
|
1520
|
+
if (obligationObjectResponse.data && obligationObjectResponse?.data?.content?.dataType === "moveObject" && "lock_key" in obligationObjectResponse.data.content.fields) {
|
|
1521
|
+
obligationLocked = Boolean(
|
|
1522
|
+
obligationObjectResponse.data.content.fields.lock_key
|
|
1523
|
+
);
|
|
1524
|
+
}
|
|
1525
|
+
return obligationLocked;
|
|
1526
|
+
};
|
|
1352
1527
|
var queryObligation = async (query, obligationId) => {
|
|
1353
1528
|
const packageId = query.address.get("core.packages.query.id");
|
|
1354
1529
|
const queryTarget = `${packageId}::obligation_query::obligation_data`;
|
|
@@ -1523,7 +1698,7 @@ var getMarketCoinAmount = async (query, marketCoinName, ownerAddress) => {
|
|
|
1523
1698
|
};
|
|
1524
1699
|
|
|
1525
1700
|
// src/queries/spoolQuery.ts
|
|
1526
|
-
var
|
|
1701
|
+
var import_utils3 = require("@mysten/sui.js/utils");
|
|
1527
1702
|
var getSpools = async (query, stakeMarketCoinNames) => {
|
|
1528
1703
|
stakeMarketCoinNames = stakeMarketCoinNames || [...SUPPORT_SPOOLS];
|
|
1529
1704
|
const stakeCoinNames = stakeMarketCoinNames.map(
|
|
@@ -1544,31 +1719,31 @@ var getSpools = async (query, stakeMarketCoinNames) => {
|
|
|
1544
1719
|
}
|
|
1545
1720
|
return spools;
|
|
1546
1721
|
};
|
|
1547
|
-
var getSpool = async (query,
|
|
1548
|
-
const
|
|
1549
|
-
marketPool = marketPool || await query.getMarketPool(
|
|
1550
|
-
const poolId = query.address.get(`spool.pools.${
|
|
1722
|
+
var getSpool = async (query, marketCoinName, marketPool) => {
|
|
1723
|
+
const coinName = query.utils.parseCoinName(marketCoinName);
|
|
1724
|
+
marketPool = marketPool || await query.getMarketPool(coinName);
|
|
1725
|
+
const poolId = query.address.get(`spool.pools.${marketCoinName}.id`);
|
|
1551
1726
|
const rewardPoolId = query.address.get(
|
|
1552
|
-
`spool.pools.${
|
|
1727
|
+
`spool.pools.${marketCoinName}.rewardPoolId`
|
|
1553
1728
|
);
|
|
1554
1729
|
let spool = void 0;
|
|
1555
|
-
const
|
|
1730
|
+
const spoolObjectResponse = await query.suiKit.client().multiGetObjects({
|
|
1556
1731
|
ids: [poolId, rewardPoolId],
|
|
1557
1732
|
options: {
|
|
1558
1733
|
showContent: true
|
|
1559
1734
|
}
|
|
1560
1735
|
});
|
|
1561
|
-
if (marketPool &&
|
|
1562
|
-
const
|
|
1736
|
+
if (marketPool && spoolObjectResponse[0].data && spoolObjectResponse[1].data) {
|
|
1737
|
+
const rewardCoinName = query.utils.getSpoolRewardCoinName(marketCoinName);
|
|
1563
1738
|
const coinPrices = await query.utils.getCoinPrices([
|
|
1564
|
-
|
|
1565
|
-
|
|
1739
|
+
coinName,
|
|
1740
|
+
rewardCoinName
|
|
1566
1741
|
]);
|
|
1567
|
-
const
|
|
1568
|
-
const rewardPoolObject =
|
|
1569
|
-
if (
|
|
1570
|
-
const fields =
|
|
1571
|
-
const
|
|
1742
|
+
const spoolObject = spoolObjectResponse[0].data;
|
|
1743
|
+
const rewardPoolObject = spoolObjectResponse[1].data;
|
|
1744
|
+
if (spoolObject.content && "fields" in spoolObject.content) {
|
|
1745
|
+
const fields = spoolObject.content.fields;
|
|
1746
|
+
const parsedSpoolData = parseOriginSpoolData({
|
|
1572
1747
|
stakeType: fields.stake_type,
|
|
1573
1748
|
maxDistributedPoint: fields.max_distributed_point,
|
|
1574
1749
|
distributedPoint: fields.distributed_point,
|
|
@@ -1580,43 +1755,48 @@ var getSpool = async (query, stakeMarketCoinName, marketPool) => {
|
|
|
1580
1755
|
createdAt: fields.created_at,
|
|
1581
1756
|
lastUpdate: fields.last_update
|
|
1582
1757
|
});
|
|
1583
|
-
const
|
|
1584
|
-
const
|
|
1585
|
-
const
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1758
|
+
const marketCoinPrice = (coinPrices?.[coinName] ?? 0) * marketPool.conversionRate;
|
|
1759
|
+
const marketCoinDecimal = query.utils.getCoinDecimal(marketCoinName);
|
|
1760
|
+
const calculatedSpoolData = calculateSpoolData(
|
|
1761
|
+
parsedSpoolData,
|
|
1762
|
+
marketCoinPrice,
|
|
1763
|
+
marketCoinDecimal
|
|
1589
1764
|
);
|
|
1590
1765
|
if (rewardPoolObject.content && "fields" in rewardPoolObject.content) {
|
|
1591
1766
|
const fields2 = rewardPoolObject.content.fields;
|
|
1592
|
-
const
|
|
1767
|
+
const parsedSpoolRewardPoolData = parseOriginSpoolRewardPoolData({
|
|
1593
1768
|
claimed_rewards: fields2.claimed_rewards,
|
|
1594
1769
|
exchange_rate_numerator: fields2.exchange_rate_numerator,
|
|
1595
1770
|
exchange_rate_denominator: fields2.exchange_rate_denominator,
|
|
1596
1771
|
rewards: fields2.rewards,
|
|
1597
1772
|
spool_id: fields2.spool_id
|
|
1598
1773
|
});
|
|
1599
|
-
const rewardCoinPrice = coinPrices?.[
|
|
1600
|
-
const rewardCoinDecimal = query.utils.getCoinDecimal(
|
|
1601
|
-
const calculatedRewardPoolData =
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1774
|
+
const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
|
|
1775
|
+
const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
1776
|
+
const calculatedRewardPoolData = calculateSpoolRewardPoolData(
|
|
1777
|
+
parsedSpoolData,
|
|
1778
|
+
parsedSpoolRewardPoolData,
|
|
1779
|
+
calculatedSpoolData,
|
|
1605
1780
|
rewardCoinPrice,
|
|
1606
1781
|
rewardCoinDecimal
|
|
1607
1782
|
);
|
|
1608
1783
|
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
|
|
1784
|
+
marketCoinName,
|
|
1785
|
+
symbol: query.utils.parseSymbol(marketCoinName),
|
|
1786
|
+
coinType: query.utils.parseCoinType(coinName),
|
|
1787
|
+
marketCoinType: query.utils.parseMarketCoinType(coinName),
|
|
1788
|
+
rewardCoinType: isMarketCoin(rewardCoinName) ? query.utils.parseMarketCoinType(rewardCoinName) : query.utils.parseCoinType(rewardCoinName),
|
|
1789
|
+
coinDecimal: query.utils.getCoinDecimal(coinName),
|
|
1790
|
+
rewardCoinDecimal: query.utils.getCoinDecimal(rewardCoinName),
|
|
1791
|
+
coinPrice: coinPrices?.[coinName] ?? 0,
|
|
1792
|
+
marketCoinPrice,
|
|
1618
1793
|
rewardCoinPrice,
|
|
1619
|
-
|
|
1794
|
+
maxPoint: parsedSpoolData.maxPoint,
|
|
1795
|
+
distributedPoint: parsedSpoolData.distributedPoint,
|
|
1796
|
+
maxStake: parsedSpoolData.maxStake,
|
|
1797
|
+
...calculatedSpoolData,
|
|
1798
|
+
exchangeRateNumerator: parsedSpoolRewardPoolData.exchangeRateNumerator,
|
|
1799
|
+
exchangeRateDenominator: parsedSpoolRewardPoolData.exchangeRateDenominator,
|
|
1620
1800
|
...calculatedRewardPoolData
|
|
1621
1801
|
};
|
|
1622
1802
|
}
|
|
@@ -1674,7 +1854,7 @@ var getStakeAccounts = async (query, ownerAddress) => {
|
|
|
1674
1854
|
const index = Number(fields.index);
|
|
1675
1855
|
const points = Number(fields.points);
|
|
1676
1856
|
const totalPoints = Number(fields.total_points);
|
|
1677
|
-
if ((0,
|
|
1857
|
+
if ((0, import_utils3.normalizeStructTag)(type) === stakeMarketCoinTypes.ssui) {
|
|
1678
1858
|
stakeAccounts.ssui.push({
|
|
1679
1859
|
id,
|
|
1680
1860
|
type,
|
|
@@ -1685,7 +1865,7 @@ var getStakeAccounts = async (query, ownerAddress) => {
|
|
|
1685
1865
|
points,
|
|
1686
1866
|
totalPoints
|
|
1687
1867
|
});
|
|
1688
|
-
} else if ((0,
|
|
1868
|
+
} else if ((0, import_utils3.normalizeStructTag)(type) === stakeMarketCoinTypes.susdc) {
|
|
1689
1869
|
stakeAccounts.susdc.push({
|
|
1690
1870
|
id,
|
|
1691
1871
|
type,
|
|
@@ -1696,7 +1876,7 @@ var getStakeAccounts = async (query, ownerAddress) => {
|
|
|
1696
1876
|
points,
|
|
1697
1877
|
totalPoints
|
|
1698
1878
|
});
|
|
1699
|
-
} else if ((0,
|
|
1879
|
+
} else if ((0, import_utils3.normalizeStructTag)(type) === stakeMarketCoinTypes.susdt) {
|
|
1700
1880
|
stakeAccounts.susdt.push({
|
|
1701
1881
|
id,
|
|
1702
1882
|
type,
|
|
@@ -1756,30 +1936,30 @@ var getStakePool = async (query, marketCoinName) => {
|
|
|
1756
1936
|
}
|
|
1757
1937
|
return stakePool;
|
|
1758
1938
|
};
|
|
1759
|
-
var
|
|
1939
|
+
var getStakeRewardPool = async (query, marketCoinName) => {
|
|
1760
1940
|
const poolId = query.address.get(
|
|
1761
1941
|
`spool.pools.${marketCoinName}.rewardPoolId`
|
|
1762
1942
|
);
|
|
1763
|
-
let
|
|
1764
|
-
const
|
|
1943
|
+
let stakeRewardPool = void 0;
|
|
1944
|
+
const stakeRewardPoolObjectResponse = await query.suiKit.client().getObject({
|
|
1765
1945
|
id: poolId,
|
|
1766
1946
|
options: {
|
|
1767
1947
|
showContent: true,
|
|
1768
1948
|
showType: true
|
|
1769
1949
|
}
|
|
1770
1950
|
});
|
|
1771
|
-
if (
|
|
1772
|
-
const
|
|
1773
|
-
const id =
|
|
1774
|
-
const type =
|
|
1775
|
-
if (
|
|
1776
|
-
const fields =
|
|
1951
|
+
if (stakeRewardPoolObjectResponse.data) {
|
|
1952
|
+
const stakeRewardPoolObject = stakeRewardPoolObjectResponse.data;
|
|
1953
|
+
const id = stakeRewardPoolObject.objectId;
|
|
1954
|
+
const type = stakeRewardPoolObject.type;
|
|
1955
|
+
if (stakeRewardPoolObject.content && "fields" in stakeRewardPoolObject.content) {
|
|
1956
|
+
const fields = stakeRewardPoolObject.content.fields;
|
|
1777
1957
|
const stakePoolId = String(fields.spool_id);
|
|
1778
1958
|
const ratioNumerator = Number(fields.exchange_rate_numerator);
|
|
1779
1959
|
const ratioDenominator = Number(fields.exchange_rate_denominator);
|
|
1780
1960
|
const rewards = Number(fields.rewards);
|
|
1781
1961
|
const claimedRewards = Number(fields.claimed_rewards);
|
|
1782
|
-
|
|
1962
|
+
stakeRewardPool = {
|
|
1783
1963
|
id,
|
|
1784
1964
|
type,
|
|
1785
1965
|
stakePoolId,
|
|
@@ -1790,7 +1970,106 @@ var getRewardPool = async (query, marketCoinName) => {
|
|
|
1790
1970
|
};
|
|
1791
1971
|
}
|
|
1792
1972
|
}
|
|
1793
|
-
return
|
|
1973
|
+
return stakeRewardPool;
|
|
1974
|
+
};
|
|
1975
|
+
|
|
1976
|
+
// src/queries/borrowIncentiveQuery.ts
|
|
1977
|
+
var import_sui_kit2 = require("@scallop-io/sui-kit");
|
|
1978
|
+
var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames) => {
|
|
1979
|
+
borrowIncentiveCoinNames = borrowIncentiveCoinNames || [
|
|
1980
|
+
...SUPPORT_BORROW_INCENTIVE_POOLS
|
|
1981
|
+
];
|
|
1982
|
+
const queryPkgId = query.address.get("borrowIncentive.query");
|
|
1983
|
+
const incentivePoolsId = query.address.get("borrowIncentive.incentivePools");
|
|
1984
|
+
const txBlock = new import_sui_kit2.SuiTxBlock();
|
|
1985
|
+
const queryTarget = `${queryPkgId}::incentive_pools_query::incentive_pools_data`;
|
|
1986
|
+
txBlock.moveCall(queryTarget, [incentivePoolsId], ["0x2::sui::SUI"]);
|
|
1987
|
+
const queryResult = await query.suiKit.inspectTxn(txBlock);
|
|
1988
|
+
const borrowIncentivePoolsQueryData = queryResult.events[0].parsedJson;
|
|
1989
|
+
const parsedBorrowIncentiveRewardPoolData = parseOriginBorrowIncentiveRewardPoolData(
|
|
1990
|
+
borrowIncentivePoolsQueryData.reward_pool
|
|
1991
|
+
);
|
|
1992
|
+
const rewardCoinType = parsedBorrowIncentiveRewardPoolData.rewardType;
|
|
1993
|
+
const borrowIncentivePools = {};
|
|
1994
|
+
for (const pool of borrowIncentivePoolsQueryData.incentive_pools) {
|
|
1995
|
+
const coinType = "0x" + pool.pool_type.name;
|
|
1996
|
+
const coinName = query.utils.parseCoinNameFromType(coinType);
|
|
1997
|
+
const rewardCoinName = query.utils.parseCoinNameFromType(rewardCoinType);
|
|
1998
|
+
if (!borrowIncentiveCoinNames.includes(coinName)) {
|
|
1999
|
+
continue;
|
|
2000
|
+
}
|
|
2001
|
+
const coinPrices = await query.utils.getCoinPrices([
|
|
2002
|
+
coinName,
|
|
2003
|
+
rewardCoinName
|
|
2004
|
+
]);
|
|
2005
|
+
const parsedBorrowIncentivePoolData = parseOriginBorrowIncentivePoolData(pool);
|
|
2006
|
+
const coinPrice = coinPrices?.[coinName] ?? 0;
|
|
2007
|
+
const coinDecimal = query.utils.getCoinDecimal(coinName);
|
|
2008
|
+
const calculatedBorrowIncentivePoolData = calculateBorrowIncentivePoolData(
|
|
2009
|
+
parsedBorrowIncentivePoolData,
|
|
2010
|
+
coinPrice,
|
|
2011
|
+
coinDecimal
|
|
2012
|
+
);
|
|
2013
|
+
const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
|
|
2014
|
+
const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
2015
|
+
const calculatedBorrowIncentiveRewardPoolData = calculateBorrowIncentiveRewardPoolData(
|
|
2016
|
+
parsedBorrowIncentivePoolData,
|
|
2017
|
+
parsedBorrowIncentiveRewardPoolData,
|
|
2018
|
+
calculatedBorrowIncentivePoolData,
|
|
2019
|
+
rewardCoinPrice,
|
|
2020
|
+
rewardCoinDecimal
|
|
2021
|
+
);
|
|
2022
|
+
borrowIncentivePools[coinName] = {
|
|
2023
|
+
coinName,
|
|
2024
|
+
symbol: query.utils.parseSymbol(coinName),
|
|
2025
|
+
coinType,
|
|
2026
|
+
rewardCoinType,
|
|
2027
|
+
coinDecimal,
|
|
2028
|
+
rewardCoinDecimal,
|
|
2029
|
+
coinPrice,
|
|
2030
|
+
rewardCoinPrice,
|
|
2031
|
+
maxPoint: parsedBorrowIncentivePoolData.maxPoint,
|
|
2032
|
+
distributedPoint: parsedBorrowIncentivePoolData.distributedPoint,
|
|
2033
|
+
maxStake: parsedBorrowIncentivePoolData.maxStake,
|
|
2034
|
+
...calculatedBorrowIncentivePoolData,
|
|
2035
|
+
exchangeRateNumerator: parsedBorrowIncentiveRewardPoolData.exchangeRateNumerator,
|
|
2036
|
+
exchangeRateDenominator: parsedBorrowIncentiveRewardPoolData.exchangeRateDenominator,
|
|
2037
|
+
...calculatedBorrowIncentiveRewardPoolData
|
|
2038
|
+
};
|
|
2039
|
+
}
|
|
2040
|
+
return borrowIncentivePools;
|
|
2041
|
+
};
|
|
2042
|
+
var queryBorrowIncentiveAccounts = async (query, obligationId, borrowIncentiveCoinNames) => {
|
|
2043
|
+
borrowIncentiveCoinNames = borrowIncentiveCoinNames || [
|
|
2044
|
+
...SUPPORT_BORROW_INCENTIVE_POOLS
|
|
2045
|
+
];
|
|
2046
|
+
const queryPkgId = query.address.get("borrowIncentive.query");
|
|
2047
|
+
const incentiveAccountsId = query.address.get(
|
|
2048
|
+
"borrowIncentive.incentiveAccounts"
|
|
2049
|
+
);
|
|
2050
|
+
const queryTarget = `${queryPkgId}::incentive_account_query::incentive_account_data`;
|
|
2051
|
+
const txBlock = new import_sui_kit2.SuiTxBlock();
|
|
2052
|
+
txBlock.moveCall(queryTarget, [incentiveAccountsId, obligationId]);
|
|
2053
|
+
const queryResult = await query.suiKit.inspectTxn(txBlock);
|
|
2054
|
+
const borrowIncentiveAccountsQueryData = queryResult.events[0].parsedJson;
|
|
2055
|
+
const borrowIncentiveAccounts = Object.values(
|
|
2056
|
+
borrowIncentiveAccountsQueryData.incentive_states
|
|
2057
|
+
).reduce((accounts, accountData) => {
|
|
2058
|
+
const parsedBorrowIncentiveAccount = parseOriginBorrowIncentiveAccountData(accountData);
|
|
2059
|
+
const poolType = parsedBorrowIncentiveAccount.poolType;
|
|
2060
|
+
const coinName = query.utils.parseCoinNameFromType(poolType);
|
|
2061
|
+
if (borrowIncentiveCoinNames && borrowIncentiveCoinNames.includes(coinName)) {
|
|
2062
|
+
accounts[coinName] = {
|
|
2063
|
+
poolType,
|
|
2064
|
+
amount: parsedBorrowIncentiveAccount.amount,
|
|
2065
|
+
points: parsedBorrowIncentiveAccount.points,
|
|
2066
|
+
totalPoints: parsedBorrowIncentiveAccount.totalPoints,
|
|
2067
|
+
index: parsedBorrowIncentiveAccount.index
|
|
2068
|
+
};
|
|
2069
|
+
}
|
|
2070
|
+
return accounts;
|
|
2071
|
+
}, {});
|
|
2072
|
+
return borrowIncentiveAccounts;
|
|
1794
2073
|
};
|
|
1795
2074
|
|
|
1796
2075
|
// src/queries/priceQuery.ts
|
|
@@ -2206,7 +2485,7 @@ var getTotalValueLocked = async (query) => {
|
|
|
2206
2485
|
var ScallopQuery = class {
|
|
2207
2486
|
constructor(params, instance) {
|
|
2208
2487
|
this.params = params;
|
|
2209
|
-
this.suiKit = instance?.suiKit ?? new
|
|
2488
|
+
this.suiKit = instance?.suiKit ?? new import_sui_kit3.SuiKit(params);
|
|
2210
2489
|
this.address = instance?.address ?? new ScallopAddress({
|
|
2211
2490
|
id: params?.addressesId || ADDRESSES_ID,
|
|
2212
2491
|
network: params?.networkType
|
|
@@ -2422,38 +2701,60 @@ var ScallopQuery = class {
|
|
|
2422
2701
|
return await getStakePool(this, stakeMarketCoinName);
|
|
2423
2702
|
}
|
|
2424
2703
|
/**
|
|
2425
|
-
* Get reward pools data.
|
|
2704
|
+
* Get stake reward pools data.
|
|
2426
2705
|
*
|
|
2427
2706
|
* @description
|
|
2428
2707
|
* For backward compatible, it is recommended to use `getSpools` method
|
|
2429
2708
|
* to get all spools data.
|
|
2430
2709
|
*
|
|
2431
2710
|
* @param stakeMarketCoinNames - Specific an array of stake market coin name.
|
|
2432
|
-
* @return
|
|
2711
|
+
* @return Stake reward pools data.
|
|
2433
2712
|
*/
|
|
2434
|
-
async
|
|
2713
|
+
async getStakeRewardPools(stakeMarketCoinNames) {
|
|
2435
2714
|
stakeMarketCoinNames = stakeMarketCoinNames ?? [...SUPPORT_SPOOLS];
|
|
2436
|
-
const
|
|
2715
|
+
const stakeRewardPools = {};
|
|
2437
2716
|
for (const stakeMarketCoinName of stakeMarketCoinNames) {
|
|
2438
|
-
const
|
|
2439
|
-
|
|
2440
|
-
|
|
2717
|
+
const stakeRewardPool = await getStakeRewardPool(
|
|
2718
|
+
this,
|
|
2719
|
+
stakeMarketCoinName
|
|
2720
|
+
);
|
|
2721
|
+
if (stakeRewardPool) {
|
|
2722
|
+
stakeRewardPools[stakeMarketCoinName] = stakeRewardPool;
|
|
2441
2723
|
}
|
|
2442
2724
|
}
|
|
2443
|
-
return
|
|
2725
|
+
return stakeRewardPools;
|
|
2444
2726
|
}
|
|
2445
2727
|
/**
|
|
2446
|
-
* Get reward pool data.
|
|
2728
|
+
* Get stake reward pool data.
|
|
2447
2729
|
*
|
|
2448
2730
|
* @description
|
|
2449
2731
|
* For backward compatible, it is recommended to use `getSpool` method
|
|
2450
2732
|
* to get spool data.
|
|
2451
2733
|
*
|
|
2452
2734
|
* @param marketCoinName - Specific support stake market coin name.
|
|
2453
|
-
* @return
|
|
2735
|
+
* @return Stake reward pool data.
|
|
2736
|
+
*/
|
|
2737
|
+
async getStakeRewardPool(stakeMarketCoinName) {
|
|
2738
|
+
return await getStakeRewardPool(this, stakeMarketCoinName);
|
|
2739
|
+
}
|
|
2740
|
+
/**
|
|
2741
|
+
* Get borrow incentive pools data.
|
|
2742
|
+
*
|
|
2743
|
+
* @param coinNames - Specific an array of support borrow incentive coin name.
|
|
2744
|
+
* @return Borrow incentive pools data.
|
|
2454
2745
|
*/
|
|
2455
|
-
async
|
|
2456
|
-
return await
|
|
2746
|
+
async getBorrowIncentivePools(coinNames) {
|
|
2747
|
+
return await queryBorrowIncentivePools(this, coinNames);
|
|
2748
|
+
}
|
|
2749
|
+
/**
|
|
2750
|
+
* Get borrow incentive accounts data.
|
|
2751
|
+
*
|
|
2752
|
+
* @param coinNames - Specific support borrow incentive coin name.
|
|
2753
|
+
* @param ownerAddress - The owner address.
|
|
2754
|
+
* @return Borrow incentive accounts data.
|
|
2755
|
+
*/
|
|
2756
|
+
async getBorrowIncentiveAccounts(obligationId, coinNames) {
|
|
2757
|
+
return await queryBorrowIncentiveAccounts(this, obligationId, coinNames);
|
|
2457
2758
|
}
|
|
2458
2759
|
/**
|
|
2459
2760
|
* Get user lending and spool infomation for specific pools.
|
|
@@ -2517,16 +2818,25 @@ var ScallopUtils = class {
|
|
|
2517
2818
|
constructor(params, instance) {
|
|
2518
2819
|
this._priceMap = /* @__PURE__ */ new Map();
|
|
2519
2820
|
/**
|
|
2520
|
-
* Get reward type of
|
|
2821
|
+
* Get reward type of spool.
|
|
2521
2822
|
*
|
|
2522
2823
|
* @param stakeMarketCoinName - Support stake market coin.
|
|
2523
|
-
* @return
|
|
2824
|
+
* @return Spool reward coin name.
|
|
2825
|
+
*/
|
|
2826
|
+
this.getSpoolRewardCoinName = (stakeMarketCoinName) => {
|
|
2827
|
+
return spoolRewardCoins[stakeMarketCoinName];
|
|
2828
|
+
};
|
|
2829
|
+
/**
|
|
2830
|
+
* Get reward type of borrow incentive pool.
|
|
2831
|
+
*
|
|
2832
|
+
* @param borrowIncentiveCoinName - Support borrow incentive coin.
|
|
2833
|
+
* @return Borrow incentive reward coin name.
|
|
2524
2834
|
*/
|
|
2525
|
-
this.
|
|
2526
|
-
return
|
|
2835
|
+
this.getBorrowIncentiveRewardCoinName = (borrowIncentiveCoinName) => {
|
|
2836
|
+
return borrowIncentiveRewardCoins[borrowIncentiveCoinName];
|
|
2527
2837
|
};
|
|
2528
2838
|
this.params = params;
|
|
2529
|
-
this._suiKit = instance?.suiKit ?? new
|
|
2839
|
+
this._suiKit = instance?.suiKit ?? new import_sui_kit4.SuiKit(params);
|
|
2530
2840
|
this._address = instance?.address ?? new ScallopAddress({
|
|
2531
2841
|
id: params?.addressesId || ADDRESSES_ID,
|
|
2532
2842
|
network: params?.networkType
|
|
@@ -2580,7 +2890,7 @@ var ScallopUtils = class {
|
|
|
2580
2890
|
throw Error(`Coin ${coinName} is not supported`);
|
|
2581
2891
|
}
|
|
2582
2892
|
if (coinName === "sui")
|
|
2583
|
-
return (0,
|
|
2893
|
+
return (0, import_utils7.normalizeStructTag)(`${coinPackageId}::sui::SUI`);
|
|
2584
2894
|
const wormHolePckageIds = [
|
|
2585
2895
|
this._address.get("core.coins.usdc.id") ?? wormholeCoinIds.usdc,
|
|
2586
2896
|
this._address.get("core.coins.usdt.id") ?? wormholeCoinIds.usdt,
|
|
@@ -2612,7 +2922,7 @@ var ScallopUtils = class {
|
|
|
2612
2922
|
return `${PROTOCOL_OBJECT_ID}::reserve::MarketCoin<${coinType}>`;
|
|
2613
2923
|
}
|
|
2614
2924
|
parseCoinNameFromType(coinType) {
|
|
2615
|
-
coinType = (0,
|
|
2925
|
+
coinType = (0, import_utils7.normalizeStructTag)(coinType);
|
|
2616
2926
|
const coinTypeRegex = new RegExp(`((0x[^:]+::[^:]+::[^<>]+))(?![^<>]*<)`);
|
|
2617
2927
|
const coinTypeMatch = coinType.match(coinTypeRegex);
|
|
2618
2928
|
const isMarketCoinType = coinType.includes("reserve::MarketCoin");
|
|
@@ -2676,7 +2986,7 @@ var ScallopUtils = class {
|
|
|
2676
2986
|
* @param coinType - The coin type, default is 0x2::SUI::SUI.
|
|
2677
2987
|
* @return The selected transaction coin arguments.
|
|
2678
2988
|
*/
|
|
2679
|
-
async selectCoinIds(amount, coinType =
|
|
2989
|
+
async selectCoinIds(amount, coinType = import_utils7.SUI_TYPE_ARG, ownerAddress) {
|
|
2680
2990
|
ownerAddress = ownerAddress || this._suiKit.currentAddress();
|
|
2681
2991
|
const coins = await this._suiKit.suiInteractor.selectCoins(
|
|
2682
2992
|
ownerAddress,
|
|
@@ -2796,16 +3106,16 @@ var ScallopUtils = class {
|
|
|
2796
3106
|
};
|
|
2797
3107
|
|
|
2798
3108
|
// src/models/scallopBuilder.ts
|
|
2799
|
-
var
|
|
2800
|
-
var
|
|
3109
|
+
var import_utils16 = require("@mysten/sui.js/utils");
|
|
3110
|
+
var import_sui_kit8 = require("@scallop-io/sui-kit");
|
|
2801
3111
|
|
|
2802
3112
|
// src/builders/coreBuilder.ts
|
|
2803
3113
|
var import_transactions = require("@mysten/sui.js/transactions");
|
|
2804
|
-
var
|
|
2805
|
-
var
|
|
3114
|
+
var import_utils10 = require("@mysten/sui.js/utils");
|
|
3115
|
+
var import_sui_kit5 = require("@scallop-io/sui-kit");
|
|
2806
3116
|
|
|
2807
3117
|
// src/builders/oracle.ts
|
|
2808
|
-
var
|
|
3118
|
+
var import_utils9 = require("@mysten/sui.js/utils");
|
|
2809
3119
|
var import_pyth_sui_js2 = require("@pythnetwork/pyth-sui-js");
|
|
2810
3120
|
var updateOracles = async (builder, txBlock, assetCoinNames) => {
|
|
2811
3121
|
assetCoinNames = assetCoinNames ?? [
|
|
@@ -2911,39 +3221,32 @@ var priceUpdateRequest = (txBlock, packageId, xOracleId, coinType) => {
|
|
|
2911
3221
|
var confirmPriceUpdateRequest = (txBlock, packageId, xOracleId, request, coinType) => {
|
|
2912
3222
|
const target = `${packageId}::x_oracle::confirm_price_update_request`;
|
|
2913
3223
|
const typeArgs = [coinType];
|
|
2914
|
-
txBlock.moveCall(target, [xOracleId, request,
|
|
3224
|
+
txBlock.moveCall(target, [xOracleId, request, import_utils9.SUI_CLOCK_OBJECT_ID], typeArgs);
|
|
2915
3225
|
return txBlock;
|
|
2916
3226
|
};
|
|
2917
3227
|
var updateSupraPrice = (txBlock, packageId, request, holderId, registryId, coinType) => {
|
|
2918
3228
|
txBlock.moveCall(
|
|
2919
3229
|
`${packageId}::rule::set_price`,
|
|
2920
|
-
[request, holderId, registryId,
|
|
3230
|
+
[request, holderId, registryId, import_utils9.SUI_CLOCK_OBJECT_ID],
|
|
2921
3231
|
[coinType]
|
|
2922
3232
|
);
|
|
2923
3233
|
};
|
|
2924
3234
|
var updateSwitchboardPrice = (txBlock, packageId, request, aggregatorId, registryId, coinType) => {
|
|
2925
3235
|
txBlock.moveCall(
|
|
2926
3236
|
`${packageId}::rule::set_price`,
|
|
2927
|
-
[request, aggregatorId, registryId,
|
|
3237
|
+
[request, aggregatorId, registryId, import_utils9.SUI_CLOCK_OBJECT_ID],
|
|
2928
3238
|
[coinType]
|
|
2929
3239
|
);
|
|
2930
3240
|
};
|
|
2931
3241
|
var updatePythPrice = (txBlock, packageId, request, stateId, feedObjectId, registryId, coinType) => {
|
|
2932
3242
|
txBlock.moveCall(
|
|
2933
3243
|
`${packageId}::rule::set_price`,
|
|
2934
|
-
[request, stateId, feedObjectId, registryId,
|
|
3244
|
+
[request, stateId, feedObjectId, registryId, import_utils9.SUI_CLOCK_OBJECT_ID],
|
|
2935
3245
|
[coinType]
|
|
2936
3246
|
);
|
|
2937
3247
|
};
|
|
2938
3248
|
|
|
2939
3249
|
// 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
3250
|
var requireObligationInfo = async (...params) => {
|
|
2948
3251
|
const [builder, txBlock, obligationId, obligationKey] = params;
|
|
2949
3252
|
if (params.length === 3 && obligationId)
|
|
@@ -3004,7 +3307,7 @@ var generateCoreNormalMethod = ({
|
|
|
3004
3307
|
coreIds.coinDecimalsRegistry,
|
|
3005
3308
|
amount,
|
|
3006
3309
|
coreIds.xOracle,
|
|
3007
|
-
|
|
3310
|
+
import_utils10.SUI_CLOCK_OBJECT_ID
|
|
3008
3311
|
],
|
|
3009
3312
|
[coinType]
|
|
3010
3313
|
);
|
|
@@ -3013,7 +3316,7 @@ var generateCoreNormalMethod = ({
|
|
|
3013
3316
|
const coinType = builder.utils.parseCoinType(poolCoinName);
|
|
3014
3317
|
return txBlock.moveCall(
|
|
3015
3318
|
`${coreIds.protocolPkg}::mint::mint`,
|
|
3016
|
-
[coreIds.version, coreIds.market, coin,
|
|
3319
|
+
[coreIds.version, coreIds.market, coin, import_utils10.SUI_CLOCK_OBJECT_ID],
|
|
3017
3320
|
[coinType]
|
|
3018
3321
|
);
|
|
3019
3322
|
},
|
|
@@ -3021,7 +3324,7 @@ var generateCoreNormalMethod = ({
|
|
|
3021
3324
|
const coinType = builder.utils.parseCoinType(poolCoinName);
|
|
3022
3325
|
return txBlock.moveCall(
|
|
3023
3326
|
`${coreIds.protocolPkg}::mint::mint_entry`,
|
|
3024
|
-
[coreIds.version, coreIds.market, coin,
|
|
3327
|
+
[coreIds.version, coreIds.market, coin, import_utils10.SUI_CLOCK_OBJECT_ID],
|
|
3025
3328
|
[coinType]
|
|
3026
3329
|
);
|
|
3027
3330
|
},
|
|
@@ -3029,7 +3332,7 @@ var generateCoreNormalMethod = ({
|
|
|
3029
3332
|
const coinType = builder.utils.parseCoinType(poolCoinName);
|
|
3030
3333
|
return txBlock.moveCall(
|
|
3031
3334
|
`${coreIds.protocolPkg}::redeem::redeem`,
|
|
3032
|
-
[coreIds.version, coreIds.market, marketCoin,
|
|
3335
|
+
[coreIds.version, coreIds.market, marketCoin, import_utils10.SUI_CLOCK_OBJECT_ID],
|
|
3033
3336
|
[coinType]
|
|
3034
3337
|
);
|
|
3035
3338
|
},
|
|
@@ -3037,7 +3340,7 @@ var generateCoreNormalMethod = ({
|
|
|
3037
3340
|
const coinType = builder.utils.parseCoinType(poolCoinName);
|
|
3038
3341
|
return txBlock.moveCall(
|
|
3039
3342
|
`${coreIds.protocolPkg}::redeem::redeem_entry`,
|
|
3040
|
-
[coreIds.version, coreIds.market, marketCoin,
|
|
3343
|
+
[coreIds.version, coreIds.market, marketCoin, import_utils10.SUI_CLOCK_OBJECT_ID],
|
|
3041
3344
|
[coinType]
|
|
3042
3345
|
);
|
|
3043
3346
|
},
|
|
@@ -3053,7 +3356,7 @@ var generateCoreNormalMethod = ({
|
|
|
3053
3356
|
coreIds.coinDecimalsRegistry,
|
|
3054
3357
|
amount,
|
|
3055
3358
|
coreIds.xOracle,
|
|
3056
|
-
|
|
3359
|
+
import_utils10.SUI_CLOCK_OBJECT_ID
|
|
3057
3360
|
],
|
|
3058
3361
|
[coinType]
|
|
3059
3362
|
);
|
|
@@ -3070,7 +3373,7 @@ var generateCoreNormalMethod = ({
|
|
|
3070
3373
|
coreIds.coinDecimalsRegistry,
|
|
3071
3374
|
amount,
|
|
3072
3375
|
coreIds.xOracle,
|
|
3073
|
-
|
|
3376
|
+
import_utils10.SUI_CLOCK_OBJECT_ID
|
|
3074
3377
|
],
|
|
3075
3378
|
[coinType]
|
|
3076
3379
|
);
|
|
@@ -3084,7 +3387,7 @@ var generateCoreNormalMethod = ({
|
|
|
3084
3387
|
obligation,
|
|
3085
3388
|
coreIds.market,
|
|
3086
3389
|
coin,
|
|
3087
|
-
|
|
3390
|
+
import_utils10.SUI_CLOCK_OBJECT_ID
|
|
3088
3391
|
],
|
|
3089
3392
|
[coinType]
|
|
3090
3393
|
);
|
|
@@ -3233,7 +3536,7 @@ var generateCoreQuickMethod = ({
|
|
|
3233
3536
|
};
|
|
3234
3537
|
};
|
|
3235
3538
|
var newCoreTxBlock = (builder, initTxBlock) => {
|
|
3236
|
-
const txBlock = initTxBlock instanceof import_transactions.TransactionBlock ? new
|
|
3539
|
+
const txBlock = initTxBlock instanceof import_transactions.TransactionBlock ? new import_sui_kit5.SuiTxBlock(initTxBlock) : initTxBlock ? initTxBlock : new import_sui_kit5.SuiTxBlock();
|
|
3237
3540
|
const normalMethod = generateCoreNormalMethod({
|
|
3238
3541
|
builder,
|
|
3239
3542
|
txBlock
|
|
@@ -3262,20 +3565,13 @@ var newCoreTxBlock = (builder, initTxBlock) => {
|
|
|
3262
3565
|
|
|
3263
3566
|
// src/builders/spoolBuilder.ts
|
|
3264
3567
|
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
|
-
};
|
|
3568
|
+
var import_utils12 = require("@mysten/sui.js/utils");
|
|
3569
|
+
var import_sui_kit6 = require("@scallop-io/sui-kit");
|
|
3274
3570
|
var requireStakeAccountIds = async (...params) => {
|
|
3275
3571
|
const [builder, txBlock, stakeMarketCoinName, stakeAccountId] = params;
|
|
3276
3572
|
if (params.length === 4 && stakeAccountId)
|
|
3277
3573
|
return [stakeAccountId];
|
|
3278
|
-
const sender =
|
|
3574
|
+
const sender = requireSender(txBlock);
|
|
3279
3575
|
const stakeAccounts = await getStakeAccounts(builder.query, sender);
|
|
3280
3576
|
if (stakeAccounts[stakeMarketCoinName].length === 0) {
|
|
3281
3577
|
throw new Error(`No stake account id found for sender ${sender}`);
|
|
@@ -3284,7 +3580,7 @@ var requireStakeAccountIds = async (...params) => {
|
|
|
3284
3580
|
};
|
|
3285
3581
|
var requireStakeAccounts = async (...params) => {
|
|
3286
3582
|
const [builder, txBlock, stakeMarketCoinName, stakeAccountId] = params;
|
|
3287
|
-
const sender =
|
|
3583
|
+
const sender = requireSender(txBlock);
|
|
3288
3584
|
const stakeAccounts = await getStakeAccounts(builder.query, sender);
|
|
3289
3585
|
if (stakeAccounts[stakeMarketCoinName].length === 0) {
|
|
3290
3586
|
throw new Error(`No stake account found for sender ${sender}`);
|
|
@@ -3309,7 +3605,7 @@ var generateSpoolNormalMethod = ({
|
|
|
3309
3605
|
);
|
|
3310
3606
|
return txBlock.moveCall(
|
|
3311
3607
|
`${spoolIds.spoolPkg}::user::new_spool_account`,
|
|
3312
|
-
[stakePoolId,
|
|
3608
|
+
[stakePoolId, import_utils12.SUI_CLOCK_OBJECT_ID],
|
|
3313
3609
|
[marketCoinType]
|
|
3314
3610
|
);
|
|
3315
3611
|
},
|
|
@@ -3320,7 +3616,7 @@ var generateSpoolNormalMethod = ({
|
|
|
3320
3616
|
);
|
|
3321
3617
|
txBlock.moveCall(
|
|
3322
3618
|
`${spoolIds.spoolPkg}::user::stake`,
|
|
3323
|
-
[stakePoolId, stakeAccount, coin,
|
|
3619
|
+
[stakePoolId, stakeAccount, coin, import_utils12.SUI_CLOCK_OBJECT_ID],
|
|
3324
3620
|
[marketCoinType]
|
|
3325
3621
|
);
|
|
3326
3622
|
},
|
|
@@ -3331,7 +3627,7 @@ var generateSpoolNormalMethod = ({
|
|
|
3331
3627
|
);
|
|
3332
3628
|
return txBlock.moveCall(
|
|
3333
3629
|
`${spoolIds.spoolPkg}::user::unstake`,
|
|
3334
|
-
[stakePoolId, stakeAccount, amount,
|
|
3630
|
+
[stakePoolId, stakeAccount, amount, import_utils12.SUI_CLOCK_OBJECT_ID],
|
|
3335
3631
|
[marketCoinType]
|
|
3336
3632
|
);
|
|
3337
3633
|
},
|
|
@@ -3343,11 +3639,11 @@ var generateSpoolNormalMethod = ({
|
|
|
3343
3639
|
`spool.pools.${stakeMarketCoinName}.rewardPoolId`
|
|
3344
3640
|
);
|
|
3345
3641
|
const marketCoinType = builder.utils.parseMarketCoinType(stakeMarketCoinName);
|
|
3346
|
-
const rewardCoinName =
|
|
3642
|
+
const rewardCoinName = spoolRewardCoins[stakeMarketCoinName];
|
|
3347
3643
|
const rewardCoinType = builder.utils.parseCoinType(rewardCoinName);
|
|
3348
3644
|
return txBlock.moveCall(
|
|
3349
3645
|
`${spoolIds.spoolPkg}::user::redeem_rewards`,
|
|
3350
|
-
[stakePoolId, rewardPoolId, stakeAccount,
|
|
3646
|
+
[stakePoolId, rewardPoolId, stakeAccount, import_utils12.SUI_CLOCK_OBJECT_ID],
|
|
3351
3647
|
[marketCoinType, rewardCoinType]
|
|
3352
3648
|
);
|
|
3353
3649
|
}
|
|
@@ -3359,7 +3655,7 @@ var generateSpoolQuickMethod = ({
|
|
|
3359
3655
|
}) => {
|
|
3360
3656
|
return {
|
|
3361
3657
|
stakeQuick: async (amountOrMarketCoin, stakeMarketCoinName, stakeAccountId) => {
|
|
3362
|
-
const sender =
|
|
3658
|
+
const sender = requireSender(txBlock);
|
|
3363
3659
|
const stakeAccountIds = await requireStakeAccountIds(
|
|
3364
3660
|
builder,
|
|
3365
3661
|
txBlock,
|
|
@@ -3418,17 +3714,17 @@ var generateSpoolQuickMethod = ({
|
|
|
3418
3714
|
stakeMarketCoinName,
|
|
3419
3715
|
stakeAccountId
|
|
3420
3716
|
);
|
|
3421
|
-
const
|
|
3717
|
+
const rewardCoins = [];
|
|
3422
3718
|
for (const accountId of stakeAccountIds) {
|
|
3423
3719
|
const rewardCoin = txBlock.claim(accountId, stakeMarketCoinName);
|
|
3424
|
-
|
|
3720
|
+
rewardCoins.push(rewardCoin);
|
|
3425
3721
|
}
|
|
3426
|
-
return
|
|
3722
|
+
return rewardCoins;
|
|
3427
3723
|
}
|
|
3428
3724
|
};
|
|
3429
3725
|
};
|
|
3430
3726
|
var newSpoolTxBlock = (builder, initTxBlock) => {
|
|
3431
|
-
const txBlock = initTxBlock instanceof import_transactions2.TransactionBlock ? new
|
|
3727
|
+
const txBlock = initTxBlock instanceof import_transactions2.TransactionBlock ? new import_sui_kit6.SuiTxBlock(initTxBlock) : initTxBlock ? initTxBlock : new import_sui_kit6.SuiTxBlock();
|
|
3432
3728
|
const normalMethod = generateSpoolNormalMethod({
|
|
3433
3729
|
builder,
|
|
3434
3730
|
txBlock
|
|
@@ -3455,13 +3751,183 @@ var newSpoolTxBlock = (builder, initTxBlock) => {
|
|
|
3455
3751
|
});
|
|
3456
3752
|
};
|
|
3457
3753
|
|
|
3754
|
+
// src/builders/borrowIncentiveBuilder.ts
|
|
3755
|
+
var import_transactions3 = require("@mysten/sui.js/transactions");
|
|
3756
|
+
var import_utils14 = require("@mysten/sui.js/utils");
|
|
3757
|
+
var import_sui_kit7 = require("@scallop-io/sui-kit");
|
|
3758
|
+
var requireObligationInfo2 = async (...params) => {
|
|
3759
|
+
const [builder, txBlock, obligationId, obligationKey] = params;
|
|
3760
|
+
if (params.length === 4 && obligationId && obligationKey && typeof obligationId === "string") {
|
|
3761
|
+
const obligationLocked = await getObligationLocked(
|
|
3762
|
+
builder.query,
|
|
3763
|
+
obligationId
|
|
3764
|
+
);
|
|
3765
|
+
return { obligationId, obligationKey, obligationLocked };
|
|
3766
|
+
}
|
|
3767
|
+
const sender = requireSender(txBlock);
|
|
3768
|
+
const obligations = await getObligations(builder.query, sender);
|
|
3769
|
+
if (obligations.length === 0) {
|
|
3770
|
+
throw new Error(`No obligation found for sender ${sender}`);
|
|
3771
|
+
}
|
|
3772
|
+
return {
|
|
3773
|
+
obligationId: obligations[0].id,
|
|
3774
|
+
obligationKey: obligations[0].keyId,
|
|
3775
|
+
obligationLocked: obligations[0].locked
|
|
3776
|
+
};
|
|
3777
|
+
};
|
|
3778
|
+
var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
|
|
3779
|
+
const borrowIncentiveIds = {
|
|
3780
|
+
borrowIncentivePkg: builder.address.get("borrowIncentive.id"),
|
|
3781
|
+
query: builder.address.get("borrowIncentive.query"),
|
|
3782
|
+
incentivePools: builder.address.get("borrowIncentive.incentivePools"),
|
|
3783
|
+
incentiveAccounts: builder.address.get(
|
|
3784
|
+
"borrowIncentive.incentiveAccounts"
|
|
3785
|
+
),
|
|
3786
|
+
obligationAccessStore: builder.address.get("core.obligationAccessStore")
|
|
3787
|
+
};
|
|
3788
|
+
return {
|
|
3789
|
+
stakeObligation: (obligationId, obligaionKey, coinName) => {
|
|
3790
|
+
const rewardCoinName = borrowIncentiveRewardCoins[coinName];
|
|
3791
|
+
const rewardType = builder.utils.parseCoinType(rewardCoinName);
|
|
3792
|
+
txBlock.moveCall(
|
|
3793
|
+
`${borrowIncentiveIds.borrowIncentivePkg}::user::stake`,
|
|
3794
|
+
[
|
|
3795
|
+
borrowIncentiveIds.incentivePools,
|
|
3796
|
+
borrowIncentiveIds.incentiveAccounts,
|
|
3797
|
+
obligaionKey,
|
|
3798
|
+
obligationId,
|
|
3799
|
+
borrowIncentiveIds.obligationAccessStore,
|
|
3800
|
+
import_utils14.SUI_CLOCK_OBJECT_ID
|
|
3801
|
+
],
|
|
3802
|
+
[rewardType]
|
|
3803
|
+
);
|
|
3804
|
+
},
|
|
3805
|
+
unstakeObligation: (obligationId, obligaionKey, coinName) => {
|
|
3806
|
+
const rewardCoinName = borrowIncentiveRewardCoins[coinName];
|
|
3807
|
+
const rewardType = builder.utils.parseCoinType(rewardCoinName);
|
|
3808
|
+
txBlock.moveCall(
|
|
3809
|
+
`${borrowIncentiveIds.borrowIncentivePkg}::user::unstake`,
|
|
3810
|
+
[
|
|
3811
|
+
borrowIncentiveIds.incentivePools,
|
|
3812
|
+
borrowIncentiveIds.incentiveAccounts,
|
|
3813
|
+
obligaionKey,
|
|
3814
|
+
obligationId,
|
|
3815
|
+
import_utils14.SUI_CLOCK_OBJECT_ID
|
|
3816
|
+
],
|
|
3817
|
+
[rewardType]
|
|
3818
|
+
);
|
|
3819
|
+
},
|
|
3820
|
+
claimBorrowIncentive: (obligationId, obligaionKey, coinName) => {
|
|
3821
|
+
const rewardCoinName = borrowIncentiveRewardCoins[coinName];
|
|
3822
|
+
const rewardType = builder.utils.parseCoinType(rewardCoinName);
|
|
3823
|
+
return txBlock.moveCall(
|
|
3824
|
+
`${borrowIncentiveIds.borrowIncentivePkg}::user::redeem_rewards`,
|
|
3825
|
+
[
|
|
3826
|
+
borrowIncentiveIds.incentivePools,
|
|
3827
|
+
borrowIncentiveIds.incentiveAccounts,
|
|
3828
|
+
obligaionKey,
|
|
3829
|
+
obligationId,
|
|
3830
|
+
import_utils14.SUI_CLOCK_OBJECT_ID
|
|
3831
|
+
],
|
|
3832
|
+
[rewardType]
|
|
3833
|
+
);
|
|
3834
|
+
}
|
|
3835
|
+
};
|
|
3836
|
+
};
|
|
3837
|
+
var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
|
|
3838
|
+
return {
|
|
3839
|
+
stakeObligationQuick: async (coinName, obligation, obligationKey) => {
|
|
3840
|
+
const {
|
|
3841
|
+
obligationId: obligationArg,
|
|
3842
|
+
obligationKey: obligationtKeyArg,
|
|
3843
|
+
obligationLocked
|
|
3844
|
+
} = await requireObligationInfo2(
|
|
3845
|
+
builder,
|
|
3846
|
+
txBlock,
|
|
3847
|
+
obligation,
|
|
3848
|
+
obligationKey
|
|
3849
|
+
);
|
|
3850
|
+
const unstakeObligationBeforeStake = !!txBlock.txBlock.blockData.transactions.find(
|
|
3851
|
+
(txn) => txn.kind === "MoveCall" && txn.target === `${builder.address.get("borrowIncentive.id")}::user::unstake`
|
|
3852
|
+
);
|
|
3853
|
+
if (!obligationLocked || unstakeObligationBeforeStake) {
|
|
3854
|
+
txBlock.stakeObligation(obligationArg, obligationtKeyArg, coinName);
|
|
3855
|
+
}
|
|
3856
|
+
},
|
|
3857
|
+
unstakeObligationQuick: async (coinName, obligation, obligationKey) => {
|
|
3858
|
+
const {
|
|
3859
|
+
obligationId: obligationArg,
|
|
3860
|
+
obligationKey: obligationtKeyArg,
|
|
3861
|
+
obligationLocked
|
|
3862
|
+
} = await requireObligationInfo2(
|
|
3863
|
+
builder,
|
|
3864
|
+
txBlock,
|
|
3865
|
+
obligation,
|
|
3866
|
+
obligationKey
|
|
3867
|
+
);
|
|
3868
|
+
if (obligationLocked) {
|
|
3869
|
+
txBlock.unstakeObligation(obligationArg, obligationtKeyArg, coinName);
|
|
3870
|
+
}
|
|
3871
|
+
},
|
|
3872
|
+
claimBorrowIncentiveQuick: async (coinName, obligation, obligationKey) => {
|
|
3873
|
+
const {
|
|
3874
|
+
obligationId: obligationArg,
|
|
3875
|
+
obligationKey: obligationtKeyArg
|
|
3876
|
+
} = await requireObligationInfo2(
|
|
3877
|
+
builder,
|
|
3878
|
+
txBlock,
|
|
3879
|
+
obligation,
|
|
3880
|
+
obligationKey
|
|
3881
|
+
);
|
|
3882
|
+
return txBlock.claimBorrowIncentive(
|
|
3883
|
+
obligationArg,
|
|
3884
|
+
obligationtKeyArg,
|
|
3885
|
+
coinName
|
|
3886
|
+
);
|
|
3887
|
+
}
|
|
3888
|
+
};
|
|
3889
|
+
};
|
|
3890
|
+
var newBorrowIncentiveTxBlock = (builder, initTxBlock) => {
|
|
3891
|
+
const txBlock = initTxBlock instanceof import_transactions3.TransactionBlock ? new import_sui_kit7.SuiTxBlock(initTxBlock) : initTxBlock ? initTxBlock : new import_sui_kit7.SuiTxBlock();
|
|
3892
|
+
const normalMethod = generateBorrowIncentiveNormalMethod({
|
|
3893
|
+
builder,
|
|
3894
|
+
txBlock
|
|
3895
|
+
});
|
|
3896
|
+
const normalTxBlock = new Proxy(txBlock, {
|
|
3897
|
+
get: (target, prop) => {
|
|
3898
|
+
if (prop in normalMethod) {
|
|
3899
|
+
return Reflect.get(normalMethod, prop);
|
|
3900
|
+
}
|
|
3901
|
+
return Reflect.get(target, prop);
|
|
3902
|
+
}
|
|
3903
|
+
});
|
|
3904
|
+
const quickMethod = generateBorrowIncentiveQuickMethod({
|
|
3905
|
+
builder,
|
|
3906
|
+
txBlock: normalTxBlock
|
|
3907
|
+
});
|
|
3908
|
+
return new Proxy(normalTxBlock, {
|
|
3909
|
+
get: (target, prop) => {
|
|
3910
|
+
if (prop in quickMethod) {
|
|
3911
|
+
return Reflect.get(quickMethod, prop);
|
|
3912
|
+
}
|
|
3913
|
+
return Reflect.get(target, prop);
|
|
3914
|
+
}
|
|
3915
|
+
});
|
|
3916
|
+
};
|
|
3917
|
+
|
|
3458
3918
|
// src/builders/index.ts
|
|
3459
3919
|
var newScallopTxBlock = (builder, initTxBlock) => {
|
|
3460
|
-
const
|
|
3920
|
+
const borrowIncentiveTxBlock = newBorrowIncentiveTxBlock(
|
|
3921
|
+
builder,
|
|
3922
|
+
initTxBlock
|
|
3923
|
+
);
|
|
3924
|
+
const spoolTxBlock = newSpoolTxBlock(builder, borrowIncentiveTxBlock);
|
|
3461
3925
|
const coreTxBlock = newCoreTxBlock(builder, spoolTxBlock);
|
|
3462
3926
|
return new Proxy(coreTxBlock, {
|
|
3463
3927
|
get: (target, prop) => {
|
|
3464
|
-
if (prop in
|
|
3928
|
+
if (prop in borrowIncentiveTxBlock) {
|
|
3929
|
+
return Reflect.get(borrowIncentiveTxBlock, prop);
|
|
3930
|
+
} else if (prop in spoolTxBlock) {
|
|
3465
3931
|
return Reflect.get(spoolTxBlock, prop);
|
|
3466
3932
|
}
|
|
3467
3933
|
return Reflect.get(target, prop);
|
|
@@ -3473,7 +3939,7 @@ var newScallopTxBlock = (builder, initTxBlock) => {
|
|
|
3473
3939
|
var ScallopBuilder = class {
|
|
3474
3940
|
constructor(params, instance) {
|
|
3475
3941
|
this.params = params;
|
|
3476
|
-
this.suiKit = instance?.suiKit ?? new
|
|
3942
|
+
this.suiKit = instance?.suiKit ?? new import_sui_kit8.SuiKit(params);
|
|
3477
3943
|
this.address = instance?.address ?? new ScallopAddress({
|
|
3478
3944
|
id: params?.addressesId || ADDRESSES_ID,
|
|
3479
3945
|
network: params?.networkType
|
|
@@ -3487,7 +3953,7 @@ var ScallopBuilder = class {
|
|
|
3487
3953
|
address: this.address,
|
|
3488
3954
|
query: this.query
|
|
3489
3955
|
});
|
|
3490
|
-
this.walletAddress = (0,
|
|
3956
|
+
this.walletAddress = (0, import_utils16.normalizeSuiAddress)(
|
|
3491
3957
|
params?.walletAddress || this.suiKit.currentAddress()
|
|
3492
3958
|
);
|
|
3493
3959
|
this.isTestnet = params.networkType ? params.networkType === "testnet" : false;
|
|
@@ -3563,7 +4029,7 @@ var ScallopBuilder = class {
|
|
|
3563
4029
|
var ScallopClient = class {
|
|
3564
4030
|
constructor(params, instance) {
|
|
3565
4031
|
this.params = params;
|
|
3566
|
-
this.suiKit = instance?.suiKit ?? new
|
|
4032
|
+
this.suiKit = instance?.suiKit ?? new import_sui_kit9.SuiKit(params);
|
|
3567
4033
|
this.address = instance?.address ?? new ScallopAddress({
|
|
3568
4034
|
id: params?.addressesId || ADDRESSES_ID,
|
|
3569
4035
|
network: params?.networkType
|
|
@@ -3583,7 +4049,7 @@ var ScallopClient = class {
|
|
|
3583
4049
|
query: this.query,
|
|
3584
4050
|
utils: this.utils
|
|
3585
4051
|
});
|
|
3586
|
-
this.walletAddress = (0,
|
|
4052
|
+
this.walletAddress = (0, import_utils17.normalizeSuiAddress)(
|
|
3587
4053
|
params?.walletAddress || this.suiKit.currentAddress()
|
|
3588
4054
|
);
|
|
3589
4055
|
}
|
|
@@ -3685,8 +4151,8 @@ var ScallopClient = class {
|
|
|
3685
4151
|
* @param stakeMarketCoinName - Support stake market coin.
|
|
3686
4152
|
* @return Reward pool data.
|
|
3687
4153
|
*/
|
|
3688
|
-
async
|
|
3689
|
-
return await this.query.
|
|
4154
|
+
async getStakeRewardPool(stakeMarketCoinName) {
|
|
4155
|
+
return await this.query.getStakeRewardPool(stakeMarketCoinName);
|
|
3690
4156
|
}
|
|
3691
4157
|
async openObligation(sign = true) {
|
|
3692
4158
|
const txBlock = this.builder.createTxBlock();
|
|
@@ -3958,11 +4424,84 @@ var ScallopClient = class {
|
|
|
3958
4424
|
const txBlock = this.builder.createTxBlock();
|
|
3959
4425
|
const sender = walletAddress || this.walletAddress;
|
|
3960
4426
|
txBlock.setSender(sender);
|
|
3961
|
-
const
|
|
4427
|
+
const rewardCoins = await txBlock.claimQuick(
|
|
3962
4428
|
stakeMarketCoinName,
|
|
3963
4429
|
stakeAccountId
|
|
3964
4430
|
);
|
|
3965
|
-
txBlock.transferObjects(
|
|
4431
|
+
txBlock.transferObjects(rewardCoins, sender);
|
|
4432
|
+
if (sign) {
|
|
4433
|
+
return await this.suiKit.signAndSendTxn(
|
|
4434
|
+
txBlock
|
|
4435
|
+
);
|
|
4436
|
+
} else {
|
|
4437
|
+
return txBlock.txBlock;
|
|
4438
|
+
}
|
|
4439
|
+
}
|
|
4440
|
+
/* ==================== Borrow Incentive Method ==================== */
|
|
4441
|
+
/**
|
|
4442
|
+
* stake obligaion.
|
|
4443
|
+
*
|
|
4444
|
+
* @param sign - Decide to directly sign the transaction or return the transaction block.
|
|
4445
|
+
* @param obligaionId - The obligation account object.
|
|
4446
|
+
* @param obligaionKeyId - The obligation key account object.
|
|
4447
|
+
* @param walletAddress - The wallet address of the owner.
|
|
4448
|
+
* @return Transaction block response or transaction block
|
|
4449
|
+
*/
|
|
4450
|
+
async stakeObligation(coinName, obligaionId, obligaionKeyId, sign = true, walletAddress) {
|
|
4451
|
+
const txBlock = this.builder.createTxBlock();
|
|
4452
|
+
const sender = walletAddress || this.walletAddress;
|
|
4453
|
+
txBlock.setSender(sender);
|
|
4454
|
+
await txBlock.stakeObligationQuick(coinName, obligaionId, obligaionKeyId);
|
|
4455
|
+
if (sign) {
|
|
4456
|
+
return await this.suiKit.signAndSendTxn(
|
|
4457
|
+
txBlock
|
|
4458
|
+
);
|
|
4459
|
+
} else {
|
|
4460
|
+
return txBlock.txBlock;
|
|
4461
|
+
}
|
|
4462
|
+
}
|
|
4463
|
+
/**
|
|
4464
|
+
* unstake obligaion.
|
|
4465
|
+
*
|
|
4466
|
+
* @param sign - Decide to directly sign the transaction or return the transaction block.
|
|
4467
|
+
* @param obligaionId - The obligation account object.
|
|
4468
|
+
* @param obligaionKeyId - The obligation key account object.
|
|
4469
|
+
* @param walletAddress - The wallet address of the owner.
|
|
4470
|
+
* @return Transaction block response or transaction block
|
|
4471
|
+
*/
|
|
4472
|
+
async unstakeObligation(coinName, obligaionId, obligaionKeyId, sign = true, walletAddress) {
|
|
4473
|
+
const txBlock = this.builder.createTxBlock();
|
|
4474
|
+
const sender = walletAddress || this.walletAddress;
|
|
4475
|
+
txBlock.setSender(sender);
|
|
4476
|
+
await txBlock.unstakeObligationQuick(coinName, obligaionId, obligaionKeyId);
|
|
4477
|
+
if (sign) {
|
|
4478
|
+
return await this.suiKit.signAndSendTxn(
|
|
4479
|
+
txBlock
|
|
4480
|
+
);
|
|
4481
|
+
} else {
|
|
4482
|
+
return txBlock.txBlock;
|
|
4483
|
+
}
|
|
4484
|
+
}
|
|
4485
|
+
/**
|
|
4486
|
+
* unstake market coin from the specific spool.
|
|
4487
|
+
*
|
|
4488
|
+
* @param marketCoinName - Types of mak coin.
|
|
4489
|
+
* @param amount - The amount of coins would deposit.
|
|
4490
|
+
* @param sign - Decide to directly sign the transaction or return the transaction block.
|
|
4491
|
+
* @param accountId - The stake account object.
|
|
4492
|
+
* @param walletAddress - The wallet address of the owner.
|
|
4493
|
+
* @return Transaction block response or transaction block
|
|
4494
|
+
*/
|
|
4495
|
+
async claimBorrowIncentive(coinName, obligaionId, obligaionKeyId, sign = true, walletAddress) {
|
|
4496
|
+
const txBlock = this.builder.createTxBlock();
|
|
4497
|
+
const sender = walletAddress || this.walletAddress;
|
|
4498
|
+
txBlock.setSender(sender);
|
|
4499
|
+
const rewardCoin = await txBlock.claimBorrowIncentiveQuick(
|
|
4500
|
+
coinName,
|
|
4501
|
+
obligaionId,
|
|
4502
|
+
obligaionKeyId
|
|
4503
|
+
);
|
|
4504
|
+
txBlock.transferObjects([rewardCoin], sender);
|
|
3966
4505
|
if (sign) {
|
|
3967
4506
|
return await this.suiKit.signAndSendTxn(
|
|
3968
4507
|
txBlock
|
|
@@ -3997,7 +4536,7 @@ var ScallopClient = class {
|
|
|
3997
4536
|
var Scallop = class {
|
|
3998
4537
|
constructor(params) {
|
|
3999
4538
|
this.params = params;
|
|
4000
|
-
this.suiKit = new
|
|
4539
|
+
this.suiKit = new import_sui_kit10.SuiKit(params);
|
|
4001
4540
|
this._address = new ScallopAddress({
|
|
4002
4541
|
id: params?.addressesId || ADDRESSES_ID,
|
|
4003
4542
|
network: params?.networkType
|
|
@@ -4076,12 +4615,14 @@ var Scallop = class {
|
|
|
4076
4615
|
ADDRESSES_ID,
|
|
4077
4616
|
API_BASE_URL,
|
|
4078
4617
|
PROTOCOL_OBJECT_ID,
|
|
4618
|
+
SUPPORT_BORROW_INCENTIVE_POOLS,
|
|
4619
|
+
SUPPORT_BORROW_INCENTIVE_REWARDS,
|
|
4079
4620
|
SUPPORT_COLLATERALS,
|
|
4080
4621
|
SUPPORT_ORACLES,
|
|
4081
4622
|
SUPPORT_PACKAGES,
|
|
4082
4623
|
SUPPORT_POOLS,
|
|
4083
|
-
SUPPORT_REWARD_POOLS,
|
|
4084
4624
|
SUPPORT_SPOOLS,
|
|
4625
|
+
SUPPORT_SPOOLS_REWARDS,
|
|
4085
4626
|
Scallop,
|
|
4086
4627
|
ScallopAddress,
|
|
4087
4628
|
ScallopBuilder,
|
|
@@ -4089,10 +4630,11 @@ var Scallop = class {
|
|
|
4089
4630
|
ScallopQuery,
|
|
4090
4631
|
ScallopUtils,
|
|
4091
4632
|
assetCoins,
|
|
4633
|
+
borrowIncentiveRewardCoins,
|
|
4092
4634
|
coinDecimals,
|
|
4093
4635
|
coinIds,
|
|
4094
4636
|
marketCoins,
|
|
4095
|
-
|
|
4637
|
+
spoolRewardCoins,
|
|
4096
4638
|
stakeMarketCoins,
|
|
4097
4639
|
voloCoinIds,
|
|
4098
4640
|
wormholeCoinIds
|