@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.mjs
CHANGED
|
@@ -29,7 +29,9 @@ var SUPPORT_COLLATERALS = [
|
|
|
29
29
|
"vsui"
|
|
30
30
|
];
|
|
31
31
|
var SUPPORT_SPOOLS = ["ssui", "susdc", "susdt"];
|
|
32
|
-
var
|
|
32
|
+
var SUPPORT_SPOOLS_REWARDS = ["sui"];
|
|
33
|
+
var SUPPORT_BORROW_INCENTIVE_POOLS = ["sui", "usdc"];
|
|
34
|
+
var SUPPORT_BORROW_INCENTIVE_REWARDS = ["sui"];
|
|
33
35
|
var SUPPORT_ORACLES = ["supra", "switchboard", "pyth"];
|
|
34
36
|
var SUPPORT_PACKAGES = [
|
|
35
37
|
"coinDecimalsRegistry",
|
|
@@ -102,11 +104,15 @@ var stakeMarketCoins = {
|
|
|
102
104
|
susdc: "susdc",
|
|
103
105
|
susdt: "susdt"
|
|
104
106
|
};
|
|
105
|
-
var
|
|
107
|
+
var spoolRewardCoins = {
|
|
106
108
|
ssui: "sui",
|
|
107
109
|
susdc: "sui",
|
|
108
110
|
susdt: "sui"
|
|
109
111
|
};
|
|
112
|
+
var borrowIncentiveRewardCoins = {
|
|
113
|
+
sui: "sui",
|
|
114
|
+
usdc: "sui"
|
|
115
|
+
};
|
|
110
116
|
var coinIds = {
|
|
111
117
|
sui: "0x0000000000000000000000000000000000000000000000000000000000000002",
|
|
112
118
|
eth: "0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5",
|
|
@@ -144,6 +150,7 @@ var EMPTY_ADDRESSES = {
|
|
|
144
150
|
market: "",
|
|
145
151
|
adminCap: "",
|
|
146
152
|
coinDecimalsRegistry: "",
|
|
153
|
+
obligationAccessStore: "",
|
|
147
154
|
coins: {
|
|
148
155
|
btc: {
|
|
149
156
|
id: "",
|
|
@@ -327,6 +334,13 @@ var EMPTY_ADDRESSES = {
|
|
|
327
334
|
rewardPoolId: ""
|
|
328
335
|
}
|
|
329
336
|
}
|
|
337
|
+
},
|
|
338
|
+
borrowIncentive: {
|
|
339
|
+
id: "",
|
|
340
|
+
adminCap: "",
|
|
341
|
+
query: "",
|
|
342
|
+
incentivePools: "",
|
|
343
|
+
incentiveAccounts: ""
|
|
330
344
|
}
|
|
331
345
|
};
|
|
332
346
|
var ScallopAddress = class {
|
|
@@ -634,7 +648,7 @@ import { normalizeSuiAddress as normalizeSuiAddress2 } from "@mysten/sui.js/util
|
|
|
634
648
|
import { SuiKit as SuiKit4 } from "@scallop-io/sui-kit";
|
|
635
649
|
|
|
636
650
|
// src/models/scallopUtils.ts
|
|
637
|
-
import { SUI_TYPE_ARG, normalizeStructTag as
|
|
651
|
+
import { SUI_TYPE_ARG, normalizeStructTag as normalizeStructTag3 } from "@mysten/sui.js/utils";
|
|
638
652
|
import { SuiKit as SuiKit2 } from "@scallop-io/sui-kit";
|
|
639
653
|
import { SuiPriceServiceConnection } from "@pythnetwork/pyth-sui-js";
|
|
640
654
|
|
|
@@ -645,28 +659,18 @@ import { SuiKit } from "@scallop-io/sui-kit";
|
|
|
645
659
|
import { SuiTxBlock as SuiKitTxBlock } from "@scallop-io/sui-kit";
|
|
646
660
|
import BigNumber2 from "bignumber.js";
|
|
647
661
|
|
|
648
|
-
// src/utils/
|
|
649
|
-
var
|
|
650
|
-
const
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
const assetCoinName = assetCoinNames.find((assetCoinName2) => {
|
|
654
|
-
return address.get(`core.coins.${assetCoinName2}.oracle.pyth.feed`) === feed.id;
|
|
655
|
-
});
|
|
656
|
-
if (assetCoinName) {
|
|
657
|
-
const price = feed.price.price * 10 ** feed.price.expo;
|
|
658
|
-
return {
|
|
659
|
-
coinName: assetCoinName,
|
|
660
|
-
price,
|
|
661
|
-
publishTime: Number(feed.price.publishTime) * 10 ** 3
|
|
662
|
-
};
|
|
663
|
-
} else {
|
|
664
|
-
throw new Error("Invalid feed id");
|
|
662
|
+
// src/utils/builder.ts
|
|
663
|
+
var requireSender = (txBlock) => {
|
|
664
|
+
const sender = txBlock.blockData.sender;
|
|
665
|
+
if (!sender) {
|
|
666
|
+
throw new Error("Sender is required");
|
|
665
667
|
}
|
|
668
|
+
return sender;
|
|
666
669
|
};
|
|
667
670
|
|
|
668
671
|
// src/utils/query.ts
|
|
669
672
|
import BigNumber from "bignumber.js";
|
|
673
|
+
import { normalizeStructTag } from "@mysten/sui.js/utils";
|
|
670
674
|
var parseOriginMarketPoolData = (originMarketPoolData) => {
|
|
671
675
|
return {
|
|
672
676
|
coinType: "0x" + originMarketPoolData.type.name,
|
|
@@ -793,48 +797,48 @@ var calculateMarketCollateralData = (utils, parsedMarketCollateralData) => {
|
|
|
793
797
|
depositCoin: depositCoin.toNumber()
|
|
794
798
|
};
|
|
795
799
|
};
|
|
796
|
-
var
|
|
800
|
+
var parseOriginSpoolData = (originSpoolData) => {
|
|
797
801
|
return {
|
|
798
|
-
stakeType: "0x" +
|
|
799
|
-
maxPoint: Number(
|
|
800
|
-
distributedPoint: Number(
|
|
801
|
-
pointPerPeriod: Number(
|
|
802
|
-
period: Number(
|
|
803
|
-
maxStake: Number(
|
|
804
|
-
staked: Number(
|
|
805
|
-
index: Number(
|
|
806
|
-
createdAt: Number(
|
|
807
|
-
lastUpdate: Number(
|
|
802
|
+
stakeType: "0x" + originSpoolData.stakeType.fields.name,
|
|
803
|
+
maxPoint: Number(originSpoolData.maxDistributedPoint),
|
|
804
|
+
distributedPoint: Number(originSpoolData.distributedPoint),
|
|
805
|
+
pointPerPeriod: Number(originSpoolData.distributedPointPerPeriod),
|
|
806
|
+
period: Number(originSpoolData.pointDistributionTime),
|
|
807
|
+
maxStake: Number(originSpoolData.maxStake),
|
|
808
|
+
staked: Number(originSpoolData.stakes),
|
|
809
|
+
index: Number(originSpoolData.index),
|
|
810
|
+
createdAt: Number(originSpoolData.createdAt),
|
|
811
|
+
lastUpdate: Number(originSpoolData.lastUpdate)
|
|
808
812
|
};
|
|
809
813
|
};
|
|
810
|
-
var
|
|
814
|
+
var calculateSpoolData = (parsedSpoolData, stakeMarketCoinPrice, stakeMarketCoinDecimal) => {
|
|
811
815
|
const baseIndexRate = 1e9;
|
|
812
816
|
const distributedPointPerSec = BigNumber(
|
|
813
|
-
|
|
814
|
-
).dividedBy(
|
|
815
|
-
const pointPerSec = BigNumber(
|
|
816
|
-
|
|
817
|
+
parsedSpoolData.pointPerPeriod
|
|
818
|
+
).dividedBy(parsedSpoolData.period);
|
|
819
|
+
const pointPerSec = BigNumber(parsedSpoolData.pointPerPeriod).dividedBy(
|
|
820
|
+
parsedSpoolData.period
|
|
817
821
|
);
|
|
818
|
-
const remainingPeriod = BigNumber(
|
|
819
|
-
const startDate =
|
|
820
|
-
const endDate = remainingPeriod.plus(
|
|
822
|
+
const remainingPeriod = BigNumber(parsedSpoolData.maxPoint).minus(parsedSpoolData.distributedPoint).dividedBy(pointPerSec);
|
|
823
|
+
const startDate = parsedSpoolData.createdAt;
|
|
824
|
+
const endDate = remainingPeriod.plus(parsedSpoolData.lastUpdate).integerValue().toNumber();
|
|
821
825
|
const timeDelta = BigNumber(
|
|
822
|
-
Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) -
|
|
823
|
-
).dividedBy(
|
|
824
|
-
const remainingPoints = BigNumber(
|
|
825
|
-
|
|
826
|
+
Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) - parsedSpoolData.lastUpdate
|
|
827
|
+
).dividedBy(parsedSpoolData.period).toFixed(0);
|
|
828
|
+
const remainingPoints = BigNumber(parsedSpoolData.maxPoint).minus(
|
|
829
|
+
parsedSpoolData.distributedPoint
|
|
826
830
|
);
|
|
827
831
|
const accumulatedPoints = BigNumber.minimum(
|
|
828
|
-
BigNumber(timeDelta).multipliedBy(
|
|
832
|
+
BigNumber(timeDelta).multipliedBy(parsedSpoolData.pointPerPeriod),
|
|
829
833
|
remainingPoints
|
|
830
834
|
);
|
|
831
|
-
const currentPointIndex = BigNumber(
|
|
832
|
-
accumulatedPoints.dividedBy(
|
|
835
|
+
const currentPointIndex = BigNumber(parsedSpoolData.index).plus(
|
|
836
|
+
accumulatedPoints.dividedBy(parsedSpoolData.staked).isFinite() ? BigNumber(baseIndexRate).multipliedBy(accumulatedPoints).dividedBy(parsedSpoolData.staked) : 0
|
|
833
837
|
);
|
|
834
838
|
const currentTotalDistributedPoint = BigNumber(
|
|
835
|
-
|
|
839
|
+
parsedSpoolData.distributedPoint
|
|
836
840
|
).plus(accumulatedPoints);
|
|
837
|
-
const stakedAmount = BigNumber(
|
|
841
|
+
const stakedAmount = BigNumber(parsedSpoolData.staked);
|
|
838
842
|
const stakedCoin = stakedAmount.shiftedBy(-1 * stakeMarketCoinDecimal);
|
|
839
843
|
const stakedValue = stakedCoin.multipliedBy(stakeMarketCoinPrice);
|
|
840
844
|
return {
|
|
@@ -849,35 +853,154 @@ var calculateStakePoolData = (parsedStakePoolData, stakeMarketCoinPrice, stakeMa
|
|
|
849
853
|
stakedValue: stakedValue.toNumber()
|
|
850
854
|
};
|
|
851
855
|
};
|
|
852
|
-
var
|
|
856
|
+
var parseOriginSpoolRewardPoolData = (originSpoolRewardPoolData) => {
|
|
857
|
+
return {
|
|
858
|
+
claimedRewards: Number(originSpoolRewardPoolData.claimed_rewards),
|
|
859
|
+
exchangeRateNumerator: Number(
|
|
860
|
+
originSpoolRewardPoolData.exchange_rate_numerator
|
|
861
|
+
),
|
|
862
|
+
exchangeRateDenominator: Number(
|
|
863
|
+
originSpoolRewardPoolData.exchange_rate_denominator
|
|
864
|
+
),
|
|
865
|
+
rewards: Number(originSpoolRewardPoolData.rewards),
|
|
866
|
+
spoolId: String(originSpoolRewardPoolData.spool_id)
|
|
867
|
+
};
|
|
868
|
+
};
|
|
869
|
+
var calculateSpoolRewardPoolData = (parsedSpoolData, parsedSpoolRewardPoolData, calculatedSpoolData, rewardCoinPrice, rewardCoinDecimal) => {
|
|
870
|
+
const rateYearFactor = 365 * 24 * 60 * 60;
|
|
871
|
+
const rewardPerSec = BigNumber(calculatedSpoolData.distributedPointPerSec).multipliedBy(parsedSpoolRewardPoolData.exchangeRateNumerator).dividedBy(parsedSpoolRewardPoolData.exchangeRateDenominator);
|
|
872
|
+
const totalRewardAmount = BigNumber(parsedSpoolData.maxPoint).multipliedBy(parsedSpoolRewardPoolData.exchangeRateNumerator).dividedBy(parsedSpoolRewardPoolData.exchangeRateDenominator);
|
|
873
|
+
const totalRewardCoin = totalRewardAmount.shiftedBy(-1 * rewardCoinDecimal);
|
|
874
|
+
const totalRewardValue = totalRewardCoin.multipliedBy(rewardCoinPrice);
|
|
875
|
+
const remaindRewardAmount = BigNumber(parsedSpoolRewardPoolData.rewards);
|
|
876
|
+
const remaindRewardCoin = remaindRewardAmount.shiftedBy(
|
|
877
|
+
-1 * rewardCoinDecimal
|
|
878
|
+
);
|
|
879
|
+
const remaindRewardValue = remaindRewardCoin.multipliedBy(rewardCoinPrice);
|
|
880
|
+
const claimedRewardAmount = BigNumber(
|
|
881
|
+
parsedSpoolRewardPoolData.claimedRewards
|
|
882
|
+
);
|
|
883
|
+
const claimedRewardCoin = claimedRewardAmount.shiftedBy(
|
|
884
|
+
-1 * rewardCoinDecimal
|
|
885
|
+
);
|
|
886
|
+
const claimedRewardValue = claimedRewardCoin.multipliedBy(rewardCoinPrice);
|
|
887
|
+
const rewardValueForYear = BigNumber(rewardPerSec).shiftedBy(-1 * rewardCoinDecimal).multipliedBy(rateYearFactor).multipliedBy(rewardCoinPrice);
|
|
888
|
+
const rewardRate = rewardValueForYear.dividedBy(calculatedSpoolData.stakedValue).isFinite() ? rewardValueForYear.dividedBy(calculatedSpoolData.stakedValue).toNumber() : Infinity;
|
|
889
|
+
return {
|
|
890
|
+
rewardApr: rewardRate,
|
|
891
|
+
totalRewardAmount: totalRewardAmount.toNumber(),
|
|
892
|
+
totalRewardCoin: totalRewardCoin.toNumber(),
|
|
893
|
+
totalRewardValue: totalRewardValue.toNumber(),
|
|
894
|
+
remaindRewardAmount: remaindRewardAmount.toNumber(),
|
|
895
|
+
remaindRewardCoin: remaindRewardCoin.toNumber(),
|
|
896
|
+
remaindRewardValue: remaindRewardValue.toNumber(),
|
|
897
|
+
claimedRewardAmount: claimedRewardAmount.toNumber(),
|
|
898
|
+
claimedRewardCoin: claimedRewardCoin.toNumber(),
|
|
899
|
+
claimedRewardValue: claimedRewardValue.toNumber(),
|
|
900
|
+
rewardPerSec: rewardPerSec.toNumber()
|
|
901
|
+
};
|
|
902
|
+
};
|
|
903
|
+
var parseOriginBorrowIncentivePoolData = (originBorrowIncentivePoolData) => {
|
|
904
|
+
return {
|
|
905
|
+
poolType: normalizeStructTag(originBorrowIncentivePoolData.pool_type.name),
|
|
906
|
+
maxPoint: Number(originBorrowIncentivePoolData.max_distributed_point),
|
|
907
|
+
distributedPoint: Number(originBorrowIncentivePoolData.distributed_point),
|
|
908
|
+
pointPerPeriod: Number(
|
|
909
|
+
originBorrowIncentivePoolData.distributed_point_per_period
|
|
910
|
+
),
|
|
911
|
+
period: Number(originBorrowIncentivePoolData.point_distribution_time),
|
|
912
|
+
maxStake: Number(originBorrowIncentivePoolData.max_stakes),
|
|
913
|
+
staked: Number(originBorrowIncentivePoolData.stakes),
|
|
914
|
+
index: Number(originBorrowIncentivePoolData.index),
|
|
915
|
+
createdAt: Number(originBorrowIncentivePoolData.created_at),
|
|
916
|
+
lastUpdate: Number(originBorrowIncentivePoolData.last_update)
|
|
917
|
+
};
|
|
918
|
+
};
|
|
919
|
+
var calculateBorrowIncentivePoolData = (parsedBorrowIncentivePoolData, borrowIncentiveCoinPrice, borrowIncentiveCoinDecimal) => {
|
|
920
|
+
const baseIndexRate = 1e9;
|
|
921
|
+
const distributedPointPerSec = BigNumber(
|
|
922
|
+
parsedBorrowIncentivePoolData.pointPerPeriod
|
|
923
|
+
).dividedBy(parsedBorrowIncentivePoolData.period);
|
|
924
|
+
const pointPerSec = BigNumber(
|
|
925
|
+
parsedBorrowIncentivePoolData.pointPerPeriod
|
|
926
|
+
).dividedBy(parsedBorrowIncentivePoolData.period);
|
|
927
|
+
const remainingPeriod = BigNumber(parsedBorrowIncentivePoolData.maxPoint).minus(parsedBorrowIncentivePoolData.distributedPoint).dividedBy(pointPerSec);
|
|
928
|
+
const startDate = parsedBorrowIncentivePoolData.createdAt;
|
|
929
|
+
const endDate = remainingPeriod.plus(parsedBorrowIncentivePoolData.lastUpdate).integerValue().toNumber();
|
|
930
|
+
const timeDelta = BigNumber(
|
|
931
|
+
Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) - parsedBorrowIncentivePoolData.lastUpdate
|
|
932
|
+
).dividedBy(parsedBorrowIncentivePoolData.period).toFixed(0);
|
|
933
|
+
const remainingPoints = BigNumber(
|
|
934
|
+
parsedBorrowIncentivePoolData.maxPoint
|
|
935
|
+
).minus(parsedBorrowIncentivePoolData.distributedPoint);
|
|
936
|
+
const accumulatedPoints = BigNumber.minimum(
|
|
937
|
+
BigNumber(timeDelta).multipliedBy(
|
|
938
|
+
parsedBorrowIncentivePoolData.pointPerPeriod
|
|
939
|
+
),
|
|
940
|
+
remainingPoints
|
|
941
|
+
);
|
|
942
|
+
const currentPointIndex = BigNumber(parsedBorrowIncentivePoolData.index).plus(
|
|
943
|
+
accumulatedPoints.dividedBy(parsedBorrowIncentivePoolData.staked).isFinite() ? BigNumber(baseIndexRate).multipliedBy(accumulatedPoints).dividedBy(parsedBorrowIncentivePoolData.staked) : 0
|
|
944
|
+
);
|
|
945
|
+
const currentTotalDistributedPoint = BigNumber(
|
|
946
|
+
parsedBorrowIncentivePoolData.distributedPoint
|
|
947
|
+
).plus(accumulatedPoints);
|
|
948
|
+
const stakedAmount = BigNumber(parsedBorrowIncentivePoolData.staked);
|
|
949
|
+
const stakedCoin = stakedAmount.shiftedBy(-1 * borrowIncentiveCoinDecimal);
|
|
950
|
+
const stakedValue = stakedCoin.multipliedBy(borrowIncentiveCoinPrice);
|
|
951
|
+
return {
|
|
952
|
+
distributedPointPerSec: distributedPointPerSec.toNumber(),
|
|
953
|
+
accumulatedPoints: accumulatedPoints.toNumber(),
|
|
954
|
+
currentPointIndex: currentPointIndex.toNumber(),
|
|
955
|
+
currentTotalDistributedPoint: currentTotalDistributedPoint.toNumber(),
|
|
956
|
+
startDate: new Date(startDate * 1e3),
|
|
957
|
+
endDate: new Date(endDate * 1e3),
|
|
958
|
+
stakedAmount: stakedAmount.toNumber(),
|
|
959
|
+
stakedCoin: stakedCoin.toNumber(),
|
|
960
|
+
stakedValue: stakedValue.toNumber()
|
|
961
|
+
};
|
|
962
|
+
};
|
|
963
|
+
var parseOriginBorrowIncentiveRewardPoolData = (originBorrowIncentiveRewardPoolData) => {
|
|
853
964
|
return {
|
|
854
|
-
|
|
855
|
-
|
|
965
|
+
rewardType: normalizeStructTag(
|
|
966
|
+
originBorrowIncentiveRewardPoolData.reward_type.name
|
|
967
|
+
),
|
|
968
|
+
claimedRewards: Number(originBorrowIncentiveRewardPoolData.claimed_rewards),
|
|
969
|
+
exchangeRateNumerator: Number(
|
|
970
|
+
originBorrowIncentiveRewardPoolData.exchange_rate_numerator
|
|
971
|
+
),
|
|
856
972
|
exchangeRateDenominator: Number(
|
|
857
|
-
|
|
973
|
+
originBorrowIncentiveRewardPoolData.exchange_rate_denominator
|
|
858
974
|
),
|
|
859
|
-
|
|
860
|
-
|
|
975
|
+
remainingRewards: Number(
|
|
976
|
+
originBorrowIncentiveRewardPoolData.remaining_reward
|
|
977
|
+
)
|
|
861
978
|
};
|
|
862
979
|
};
|
|
863
|
-
var
|
|
980
|
+
var calculateBorrowIncentiveRewardPoolData = (parsedBorrowIncentivePoolData, parsedBorrowIncentiveRewardPoolData, calculatedBorrowIncentivePoolData, rewardCoinPrice, rewardCoinDecimal) => {
|
|
864
981
|
const rateYearFactor = 365 * 24 * 60 * 60;
|
|
865
|
-
const rewardPerSec = BigNumber(
|
|
866
|
-
|
|
982
|
+
const rewardPerSec = BigNumber(
|
|
983
|
+
calculatedBorrowIncentivePoolData.distributedPointPerSec
|
|
984
|
+
).multipliedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateNumerator).dividedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateDenominator);
|
|
985
|
+
const totalRewardAmount = BigNumber(parsedBorrowIncentivePoolData.maxPoint).multipliedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateNumerator).dividedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateDenominator);
|
|
867
986
|
const totalRewardCoin = totalRewardAmount.shiftedBy(-1 * rewardCoinDecimal);
|
|
868
987
|
const totalRewardValue = totalRewardCoin.multipliedBy(rewardCoinPrice);
|
|
869
|
-
const remaindRewardAmount = BigNumber(
|
|
988
|
+
const remaindRewardAmount = BigNumber(
|
|
989
|
+
parsedBorrowIncentiveRewardPoolData.remainingRewards
|
|
990
|
+
);
|
|
870
991
|
const remaindRewardCoin = remaindRewardAmount.shiftedBy(
|
|
871
992
|
-1 * rewardCoinDecimal
|
|
872
993
|
);
|
|
873
994
|
const remaindRewardValue = remaindRewardCoin.multipliedBy(rewardCoinPrice);
|
|
874
|
-
const claimedRewardAmount = BigNumber(
|
|
995
|
+
const claimedRewardAmount = BigNumber(
|
|
996
|
+
parsedBorrowIncentiveRewardPoolData.claimedRewards
|
|
997
|
+
);
|
|
875
998
|
const claimedRewardCoin = claimedRewardAmount.shiftedBy(
|
|
876
999
|
-1 * rewardCoinDecimal
|
|
877
1000
|
);
|
|
878
1001
|
const claimedRewardValue = claimedRewardCoin.multipliedBy(rewardCoinPrice);
|
|
879
1002
|
const rewardValueForYear = BigNumber(rewardPerSec).shiftedBy(-1 * rewardCoinDecimal).multipliedBy(rateYearFactor).multipliedBy(rewardCoinPrice);
|
|
880
|
-
const rewardRate = rewardValueForYear.dividedBy(
|
|
1003
|
+
const rewardRate = rewardValueForYear.dividedBy(calculatedBorrowIncentivePoolData.stakedValue).isFinite() ? rewardValueForYear.dividedBy(calculatedBorrowIncentivePoolData.stakedValue).toNumber() : Infinity;
|
|
881
1004
|
return {
|
|
882
1005
|
rewardApr: rewardRate,
|
|
883
1006
|
totalRewardAmount: totalRewardAmount.toNumber(),
|
|
@@ -889,9 +1012,18 @@ var calculateRewardPoolData = (parsedStakePoolData, parsedRewardPoolData, calcul
|
|
|
889
1012
|
claimedRewardAmount: claimedRewardAmount.toNumber(),
|
|
890
1013
|
claimedRewardCoin: claimedRewardCoin.toNumber(),
|
|
891
1014
|
claimedRewardValue: claimedRewardValue.toNumber(),
|
|
892
|
-
rewardPerSec: rewardPerSec.toNumber()
|
|
893
|
-
|
|
894
|
-
|
|
1015
|
+
rewardPerSec: rewardPerSec.toNumber()
|
|
1016
|
+
};
|
|
1017
|
+
};
|
|
1018
|
+
var parseOriginBorrowIncentiveAccountData = (originBorrowIncentiveAccountData) => {
|
|
1019
|
+
return {
|
|
1020
|
+
poolType: normalizeStructTag(
|
|
1021
|
+
originBorrowIncentiveAccountData.pool_type.name
|
|
1022
|
+
),
|
|
1023
|
+
amount: Number(originBorrowIncentiveAccountData.amount),
|
|
1024
|
+
index: Number(originBorrowIncentiveAccountData.index),
|
|
1025
|
+
points: Number(originBorrowIncentiveAccountData.points),
|
|
1026
|
+
totalPoints: Number(originBorrowIncentiveAccountData.total_points)
|
|
895
1027
|
};
|
|
896
1028
|
};
|
|
897
1029
|
var minBigNumber = (...args) => {
|
|
@@ -909,7 +1041,7 @@ var isMarketCoin = (coinName) => {
|
|
|
909
1041
|
.../* @__PURE__ */ new Set([
|
|
910
1042
|
...SUPPORT_POOLS,
|
|
911
1043
|
...SUPPORT_COLLATERALS,
|
|
912
|
-
...
|
|
1044
|
+
...SUPPORT_SPOOLS_REWARDS
|
|
913
1045
|
])
|
|
914
1046
|
].includes(assetCoinName);
|
|
915
1047
|
};
|
|
@@ -925,6 +1057,24 @@ var parseAssetSymbol = (coinName) => {
|
|
|
925
1057
|
return coinName.toUpperCase();
|
|
926
1058
|
}
|
|
927
1059
|
};
|
|
1060
|
+
var parseDataFromPythPriceFeed = (feed, address) => {
|
|
1061
|
+
const assetCoinNames = [
|
|
1062
|
+
.../* @__PURE__ */ new Set([...SUPPORT_POOLS, ...SUPPORT_COLLATERALS])
|
|
1063
|
+
];
|
|
1064
|
+
const assetCoinName = assetCoinNames.find((assetCoinName2) => {
|
|
1065
|
+
return address.get(`core.coins.${assetCoinName2}.oracle.pyth.feed`) === feed.id;
|
|
1066
|
+
});
|
|
1067
|
+
if (assetCoinName) {
|
|
1068
|
+
const price = feed.price.price * 10 ** feed.price.expo;
|
|
1069
|
+
return {
|
|
1070
|
+
coinName: assetCoinName,
|
|
1071
|
+
price,
|
|
1072
|
+
publishTime: Number(feed.price.publishTime) * 10 ** 3
|
|
1073
|
+
};
|
|
1074
|
+
} else {
|
|
1075
|
+
throw new Error("Invalid feed id");
|
|
1076
|
+
}
|
|
1077
|
+
};
|
|
928
1078
|
|
|
929
1079
|
// src/queries/coreQuery.ts
|
|
930
1080
|
var queryMarket = async (query) => {
|
|
@@ -938,6 +1088,12 @@ var queryMarket = async (query) => {
|
|
|
938
1088
|
const pools = {};
|
|
939
1089
|
const collaterals = {};
|
|
940
1090
|
for (const pool of marketData.pools) {
|
|
1091
|
+
const coinType = "0x" + pool.type.name;
|
|
1092
|
+
const poolCoinName = query.utils.parseCoinNameFromType(coinType);
|
|
1093
|
+
const coinPrice = (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName] ?? 0;
|
|
1094
|
+
if (!SUPPORT_POOLS.includes(poolCoinName)) {
|
|
1095
|
+
continue;
|
|
1096
|
+
}
|
|
941
1097
|
const parsedMarketPoolData = parseOriginMarketPoolData({
|
|
942
1098
|
type: pool.type,
|
|
943
1099
|
maxBorrowRate: pool.maxBorrowRate,
|
|
@@ -962,9 +1118,6 @@ var queryMarket = async (query) => {
|
|
|
962
1118
|
query.utils,
|
|
963
1119
|
parsedMarketPoolData
|
|
964
1120
|
);
|
|
965
|
-
const coinType = "0x" + pool.type.name;
|
|
966
|
-
const poolCoinName = query.utils.parseCoinNameFromType(coinType);
|
|
967
|
-
const coinPrice = (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName] ?? 0;
|
|
968
1121
|
pools[poolCoinName] = {
|
|
969
1122
|
coinName: poolCoinName,
|
|
970
1123
|
symbol: query.utils.parseSymbol(poolCoinName),
|
|
@@ -983,6 +1136,12 @@ var queryMarket = async (query) => {
|
|
|
983
1136
|
};
|
|
984
1137
|
}
|
|
985
1138
|
for (const collateral of marketData.collaterals) {
|
|
1139
|
+
const coinType = "0x" + collateral.type.name;
|
|
1140
|
+
const collateralCoinName = query.utils.parseCoinNameFromType(coinType);
|
|
1141
|
+
const coinPrice = (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName] ?? 0;
|
|
1142
|
+
if (!SUPPORT_COLLATERALS.includes(collateralCoinName)) {
|
|
1143
|
+
continue;
|
|
1144
|
+
}
|
|
986
1145
|
const parsedMarketCollateralData = parseOriginMarketCollateralData({
|
|
987
1146
|
type: collateral.type,
|
|
988
1147
|
collateralFactor: collateral.collateralFactor,
|
|
@@ -997,9 +1156,6 @@ var queryMarket = async (query) => {
|
|
|
997
1156
|
query.utils,
|
|
998
1157
|
parsedMarketCollateralData
|
|
999
1158
|
);
|
|
1000
|
-
const coinType = "0x" + collateral.type.name;
|
|
1001
|
-
const collateralCoinName = query.utils.parseCoinNameFromType(coinType);
|
|
1002
|
-
const coinPrice = (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName] ?? 0;
|
|
1003
1159
|
collaterals[collateralCoinName] = {
|
|
1004
1160
|
coinName: collateralCoinName,
|
|
1005
1161
|
symbol: query.utils.parseSymbol(collateralCoinName),
|
|
@@ -1286,11 +1442,27 @@ var getObligations = async (query, ownerAddress) => {
|
|
|
1286
1442
|
if (keyObject.content && "fields" in keyObject.content) {
|
|
1287
1443
|
const fields = keyObject.content.fields;
|
|
1288
1444
|
const obligationId = String(fields.ownership.fields.of);
|
|
1289
|
-
|
|
1445
|
+
const locked = await getObligationLocked(query, obligationId);
|
|
1446
|
+
obligations.push({ id: obligationId, keyId, locked });
|
|
1290
1447
|
}
|
|
1291
1448
|
}
|
|
1292
1449
|
return obligations;
|
|
1293
1450
|
};
|
|
1451
|
+
var getObligationLocked = async (query, obligationId) => {
|
|
1452
|
+
const obligationObjectResponse = await query.suiKit.client().getObject({
|
|
1453
|
+
id: obligationId,
|
|
1454
|
+
options: {
|
|
1455
|
+
showContent: true
|
|
1456
|
+
}
|
|
1457
|
+
});
|
|
1458
|
+
let obligationLocked = false;
|
|
1459
|
+
if (obligationObjectResponse.data && obligationObjectResponse?.data?.content?.dataType === "moveObject" && "lock_key" in obligationObjectResponse.data.content.fields) {
|
|
1460
|
+
obligationLocked = Boolean(
|
|
1461
|
+
obligationObjectResponse.data.content.fields.lock_key
|
|
1462
|
+
);
|
|
1463
|
+
}
|
|
1464
|
+
return obligationLocked;
|
|
1465
|
+
};
|
|
1294
1466
|
var queryObligation = async (query, obligationId) => {
|
|
1295
1467
|
const packageId = query.address.get("core.packages.query.id");
|
|
1296
1468
|
const queryTarget = `${packageId}::obligation_query::obligation_data`;
|
|
@@ -1465,7 +1637,7 @@ var getMarketCoinAmount = async (query, marketCoinName, ownerAddress) => {
|
|
|
1465
1637
|
};
|
|
1466
1638
|
|
|
1467
1639
|
// src/queries/spoolQuery.ts
|
|
1468
|
-
import { normalizeStructTag } from "@mysten/sui.js/utils";
|
|
1640
|
+
import { normalizeStructTag as normalizeStructTag2 } from "@mysten/sui.js/utils";
|
|
1469
1641
|
var getSpools = async (query, stakeMarketCoinNames) => {
|
|
1470
1642
|
stakeMarketCoinNames = stakeMarketCoinNames || [...SUPPORT_SPOOLS];
|
|
1471
1643
|
const stakeCoinNames = stakeMarketCoinNames.map(
|
|
@@ -1486,31 +1658,31 @@ var getSpools = async (query, stakeMarketCoinNames) => {
|
|
|
1486
1658
|
}
|
|
1487
1659
|
return spools;
|
|
1488
1660
|
};
|
|
1489
|
-
var getSpool = async (query,
|
|
1490
|
-
const
|
|
1491
|
-
marketPool = marketPool || await query.getMarketPool(
|
|
1492
|
-
const poolId = query.address.get(`spool.pools.${
|
|
1661
|
+
var getSpool = async (query, marketCoinName, marketPool) => {
|
|
1662
|
+
const coinName = query.utils.parseCoinName(marketCoinName);
|
|
1663
|
+
marketPool = marketPool || await query.getMarketPool(coinName);
|
|
1664
|
+
const poolId = query.address.get(`spool.pools.${marketCoinName}.id`);
|
|
1493
1665
|
const rewardPoolId = query.address.get(
|
|
1494
|
-
`spool.pools.${
|
|
1666
|
+
`spool.pools.${marketCoinName}.rewardPoolId`
|
|
1495
1667
|
);
|
|
1496
1668
|
let spool = void 0;
|
|
1497
|
-
const
|
|
1669
|
+
const spoolObjectResponse = await query.suiKit.client().multiGetObjects({
|
|
1498
1670
|
ids: [poolId, rewardPoolId],
|
|
1499
1671
|
options: {
|
|
1500
1672
|
showContent: true
|
|
1501
1673
|
}
|
|
1502
1674
|
});
|
|
1503
|
-
if (marketPool &&
|
|
1504
|
-
const
|
|
1675
|
+
if (marketPool && spoolObjectResponse[0].data && spoolObjectResponse[1].data) {
|
|
1676
|
+
const rewardCoinName = query.utils.getSpoolRewardCoinName(marketCoinName);
|
|
1505
1677
|
const coinPrices = await query.utils.getCoinPrices([
|
|
1506
|
-
|
|
1507
|
-
|
|
1678
|
+
coinName,
|
|
1679
|
+
rewardCoinName
|
|
1508
1680
|
]);
|
|
1509
|
-
const
|
|
1510
|
-
const rewardPoolObject =
|
|
1511
|
-
if (
|
|
1512
|
-
const fields =
|
|
1513
|
-
const
|
|
1681
|
+
const spoolObject = spoolObjectResponse[0].data;
|
|
1682
|
+
const rewardPoolObject = spoolObjectResponse[1].data;
|
|
1683
|
+
if (spoolObject.content && "fields" in spoolObject.content) {
|
|
1684
|
+
const fields = spoolObject.content.fields;
|
|
1685
|
+
const parsedSpoolData = parseOriginSpoolData({
|
|
1514
1686
|
stakeType: fields.stake_type,
|
|
1515
1687
|
maxDistributedPoint: fields.max_distributed_point,
|
|
1516
1688
|
distributedPoint: fields.distributed_point,
|
|
@@ -1522,43 +1694,48 @@ var getSpool = async (query, stakeMarketCoinName, marketPool) => {
|
|
|
1522
1694
|
createdAt: fields.created_at,
|
|
1523
1695
|
lastUpdate: fields.last_update
|
|
1524
1696
|
});
|
|
1525
|
-
const
|
|
1526
|
-
const
|
|
1527
|
-
const
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1697
|
+
const marketCoinPrice = (coinPrices?.[coinName] ?? 0) * marketPool.conversionRate;
|
|
1698
|
+
const marketCoinDecimal = query.utils.getCoinDecimal(marketCoinName);
|
|
1699
|
+
const calculatedSpoolData = calculateSpoolData(
|
|
1700
|
+
parsedSpoolData,
|
|
1701
|
+
marketCoinPrice,
|
|
1702
|
+
marketCoinDecimal
|
|
1531
1703
|
);
|
|
1532
1704
|
if (rewardPoolObject.content && "fields" in rewardPoolObject.content) {
|
|
1533
1705
|
const fields2 = rewardPoolObject.content.fields;
|
|
1534
|
-
const
|
|
1706
|
+
const parsedSpoolRewardPoolData = parseOriginSpoolRewardPoolData({
|
|
1535
1707
|
claimed_rewards: fields2.claimed_rewards,
|
|
1536
1708
|
exchange_rate_numerator: fields2.exchange_rate_numerator,
|
|
1537
1709
|
exchange_rate_denominator: fields2.exchange_rate_denominator,
|
|
1538
1710
|
rewards: fields2.rewards,
|
|
1539
1711
|
spool_id: fields2.spool_id
|
|
1540
1712
|
});
|
|
1541
|
-
const rewardCoinPrice = coinPrices?.[
|
|
1542
|
-
const rewardCoinDecimal = query.utils.getCoinDecimal(
|
|
1543
|
-
const calculatedRewardPoolData =
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1713
|
+
const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
|
|
1714
|
+
const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
1715
|
+
const calculatedRewardPoolData = calculateSpoolRewardPoolData(
|
|
1716
|
+
parsedSpoolData,
|
|
1717
|
+
parsedSpoolRewardPoolData,
|
|
1718
|
+
calculatedSpoolData,
|
|
1547
1719
|
rewardCoinPrice,
|
|
1548
1720
|
rewardCoinDecimal
|
|
1549
1721
|
);
|
|
1550
1722
|
spool = {
|
|
1551
|
-
marketCoinName
|
|
1552
|
-
symbol: query.utils.parseSymbol(
|
|
1553
|
-
coinType: query.utils.parseCoinType(
|
|
1554
|
-
marketCoinType: query.utils.parseMarketCoinType(
|
|
1555
|
-
rewardCoinType: isMarketCoin(
|
|
1556
|
-
coinDecimal: query.utils.getCoinDecimal(
|
|
1557
|
-
rewardCoinDecimal: query.utils.getCoinDecimal(
|
|
1558
|
-
coinPrice: coinPrices?.[
|
|
1559
|
-
marketCoinPrice
|
|
1723
|
+
marketCoinName,
|
|
1724
|
+
symbol: query.utils.parseSymbol(marketCoinName),
|
|
1725
|
+
coinType: query.utils.parseCoinType(coinName),
|
|
1726
|
+
marketCoinType: query.utils.parseMarketCoinType(coinName),
|
|
1727
|
+
rewardCoinType: isMarketCoin(rewardCoinName) ? query.utils.parseMarketCoinType(rewardCoinName) : query.utils.parseCoinType(rewardCoinName),
|
|
1728
|
+
coinDecimal: query.utils.getCoinDecimal(coinName),
|
|
1729
|
+
rewardCoinDecimal: query.utils.getCoinDecimal(rewardCoinName),
|
|
1730
|
+
coinPrice: coinPrices?.[coinName] ?? 0,
|
|
1731
|
+
marketCoinPrice,
|
|
1560
1732
|
rewardCoinPrice,
|
|
1561
|
-
|
|
1733
|
+
maxPoint: parsedSpoolData.maxPoint,
|
|
1734
|
+
distributedPoint: parsedSpoolData.distributedPoint,
|
|
1735
|
+
maxStake: parsedSpoolData.maxStake,
|
|
1736
|
+
...calculatedSpoolData,
|
|
1737
|
+
exchangeRateNumerator: parsedSpoolRewardPoolData.exchangeRateNumerator,
|
|
1738
|
+
exchangeRateDenominator: parsedSpoolRewardPoolData.exchangeRateDenominator,
|
|
1562
1739
|
...calculatedRewardPoolData
|
|
1563
1740
|
};
|
|
1564
1741
|
}
|
|
@@ -1616,7 +1793,7 @@ var getStakeAccounts = async (query, ownerAddress) => {
|
|
|
1616
1793
|
const index = Number(fields.index);
|
|
1617
1794
|
const points = Number(fields.points);
|
|
1618
1795
|
const totalPoints = Number(fields.total_points);
|
|
1619
|
-
if (
|
|
1796
|
+
if (normalizeStructTag2(type) === stakeMarketCoinTypes.ssui) {
|
|
1620
1797
|
stakeAccounts.ssui.push({
|
|
1621
1798
|
id,
|
|
1622
1799
|
type,
|
|
@@ -1627,7 +1804,7 @@ var getStakeAccounts = async (query, ownerAddress) => {
|
|
|
1627
1804
|
points,
|
|
1628
1805
|
totalPoints
|
|
1629
1806
|
});
|
|
1630
|
-
} else if (
|
|
1807
|
+
} else if (normalizeStructTag2(type) === stakeMarketCoinTypes.susdc) {
|
|
1631
1808
|
stakeAccounts.susdc.push({
|
|
1632
1809
|
id,
|
|
1633
1810
|
type,
|
|
@@ -1638,7 +1815,7 @@ var getStakeAccounts = async (query, ownerAddress) => {
|
|
|
1638
1815
|
points,
|
|
1639
1816
|
totalPoints
|
|
1640
1817
|
});
|
|
1641
|
-
} else if (
|
|
1818
|
+
} else if (normalizeStructTag2(type) === stakeMarketCoinTypes.susdt) {
|
|
1642
1819
|
stakeAccounts.susdt.push({
|
|
1643
1820
|
id,
|
|
1644
1821
|
type,
|
|
@@ -1698,30 +1875,30 @@ var getStakePool = async (query, marketCoinName) => {
|
|
|
1698
1875
|
}
|
|
1699
1876
|
return stakePool;
|
|
1700
1877
|
};
|
|
1701
|
-
var
|
|
1878
|
+
var getStakeRewardPool = async (query, marketCoinName) => {
|
|
1702
1879
|
const poolId = query.address.get(
|
|
1703
1880
|
`spool.pools.${marketCoinName}.rewardPoolId`
|
|
1704
1881
|
);
|
|
1705
|
-
let
|
|
1706
|
-
const
|
|
1882
|
+
let stakeRewardPool = void 0;
|
|
1883
|
+
const stakeRewardPoolObjectResponse = await query.suiKit.client().getObject({
|
|
1707
1884
|
id: poolId,
|
|
1708
1885
|
options: {
|
|
1709
1886
|
showContent: true,
|
|
1710
1887
|
showType: true
|
|
1711
1888
|
}
|
|
1712
1889
|
});
|
|
1713
|
-
if (
|
|
1714
|
-
const
|
|
1715
|
-
const id =
|
|
1716
|
-
const type =
|
|
1717
|
-
if (
|
|
1718
|
-
const fields =
|
|
1890
|
+
if (stakeRewardPoolObjectResponse.data) {
|
|
1891
|
+
const stakeRewardPoolObject = stakeRewardPoolObjectResponse.data;
|
|
1892
|
+
const id = stakeRewardPoolObject.objectId;
|
|
1893
|
+
const type = stakeRewardPoolObject.type;
|
|
1894
|
+
if (stakeRewardPoolObject.content && "fields" in stakeRewardPoolObject.content) {
|
|
1895
|
+
const fields = stakeRewardPoolObject.content.fields;
|
|
1719
1896
|
const stakePoolId = String(fields.spool_id);
|
|
1720
1897
|
const ratioNumerator = Number(fields.exchange_rate_numerator);
|
|
1721
1898
|
const ratioDenominator = Number(fields.exchange_rate_denominator);
|
|
1722
1899
|
const rewards = Number(fields.rewards);
|
|
1723
1900
|
const claimedRewards = Number(fields.claimed_rewards);
|
|
1724
|
-
|
|
1901
|
+
stakeRewardPool = {
|
|
1725
1902
|
id,
|
|
1726
1903
|
type,
|
|
1727
1904
|
stakePoolId,
|
|
@@ -1732,7 +1909,106 @@ var getRewardPool = async (query, marketCoinName) => {
|
|
|
1732
1909
|
};
|
|
1733
1910
|
}
|
|
1734
1911
|
}
|
|
1735
|
-
return
|
|
1912
|
+
return stakeRewardPool;
|
|
1913
|
+
};
|
|
1914
|
+
|
|
1915
|
+
// src/queries/borrowIncentiveQuery.ts
|
|
1916
|
+
import { SuiTxBlock as SuiKitTxBlock2 } from "@scallop-io/sui-kit";
|
|
1917
|
+
var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames) => {
|
|
1918
|
+
borrowIncentiveCoinNames = borrowIncentiveCoinNames || [
|
|
1919
|
+
...SUPPORT_BORROW_INCENTIVE_POOLS
|
|
1920
|
+
];
|
|
1921
|
+
const queryPkgId = query.address.get("borrowIncentive.query");
|
|
1922
|
+
const incentivePoolsId = query.address.get("borrowIncentive.incentivePools");
|
|
1923
|
+
const txBlock = new SuiKitTxBlock2();
|
|
1924
|
+
const queryTarget = `${queryPkgId}::incentive_pools_query::incentive_pools_data`;
|
|
1925
|
+
txBlock.moveCall(queryTarget, [incentivePoolsId], ["0x2::sui::SUI"]);
|
|
1926
|
+
const queryResult = await query.suiKit.inspectTxn(txBlock);
|
|
1927
|
+
const borrowIncentivePoolsQueryData = queryResult.events[0].parsedJson;
|
|
1928
|
+
const parsedBorrowIncentiveRewardPoolData = parseOriginBorrowIncentiveRewardPoolData(
|
|
1929
|
+
borrowIncentivePoolsQueryData.reward_pool
|
|
1930
|
+
);
|
|
1931
|
+
const rewardCoinType = parsedBorrowIncentiveRewardPoolData.rewardType;
|
|
1932
|
+
const borrowIncentivePools = {};
|
|
1933
|
+
for (const pool of borrowIncentivePoolsQueryData.incentive_pools) {
|
|
1934
|
+
const coinType = "0x" + pool.pool_type.name;
|
|
1935
|
+
const coinName = query.utils.parseCoinNameFromType(coinType);
|
|
1936
|
+
const rewardCoinName = query.utils.parseCoinNameFromType(rewardCoinType);
|
|
1937
|
+
if (!borrowIncentiveCoinNames.includes(coinName)) {
|
|
1938
|
+
continue;
|
|
1939
|
+
}
|
|
1940
|
+
const coinPrices = await query.utils.getCoinPrices([
|
|
1941
|
+
coinName,
|
|
1942
|
+
rewardCoinName
|
|
1943
|
+
]);
|
|
1944
|
+
const parsedBorrowIncentivePoolData = parseOriginBorrowIncentivePoolData(pool);
|
|
1945
|
+
const coinPrice = coinPrices?.[coinName] ?? 0;
|
|
1946
|
+
const coinDecimal = query.utils.getCoinDecimal(coinName);
|
|
1947
|
+
const calculatedBorrowIncentivePoolData = calculateBorrowIncentivePoolData(
|
|
1948
|
+
parsedBorrowIncentivePoolData,
|
|
1949
|
+
coinPrice,
|
|
1950
|
+
coinDecimal
|
|
1951
|
+
);
|
|
1952
|
+
const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
|
|
1953
|
+
const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
1954
|
+
const calculatedBorrowIncentiveRewardPoolData = calculateBorrowIncentiveRewardPoolData(
|
|
1955
|
+
parsedBorrowIncentivePoolData,
|
|
1956
|
+
parsedBorrowIncentiveRewardPoolData,
|
|
1957
|
+
calculatedBorrowIncentivePoolData,
|
|
1958
|
+
rewardCoinPrice,
|
|
1959
|
+
rewardCoinDecimal
|
|
1960
|
+
);
|
|
1961
|
+
borrowIncentivePools[coinName] = {
|
|
1962
|
+
coinName,
|
|
1963
|
+
symbol: query.utils.parseSymbol(coinName),
|
|
1964
|
+
coinType,
|
|
1965
|
+
rewardCoinType,
|
|
1966
|
+
coinDecimal,
|
|
1967
|
+
rewardCoinDecimal,
|
|
1968
|
+
coinPrice,
|
|
1969
|
+
rewardCoinPrice,
|
|
1970
|
+
maxPoint: parsedBorrowIncentivePoolData.maxPoint,
|
|
1971
|
+
distributedPoint: parsedBorrowIncentivePoolData.distributedPoint,
|
|
1972
|
+
maxStake: parsedBorrowIncentivePoolData.maxStake,
|
|
1973
|
+
...calculatedBorrowIncentivePoolData,
|
|
1974
|
+
exchangeRateNumerator: parsedBorrowIncentiveRewardPoolData.exchangeRateNumerator,
|
|
1975
|
+
exchangeRateDenominator: parsedBorrowIncentiveRewardPoolData.exchangeRateDenominator,
|
|
1976
|
+
...calculatedBorrowIncentiveRewardPoolData
|
|
1977
|
+
};
|
|
1978
|
+
}
|
|
1979
|
+
return borrowIncentivePools;
|
|
1980
|
+
};
|
|
1981
|
+
var queryBorrowIncentiveAccounts = async (query, obligationId, borrowIncentiveCoinNames) => {
|
|
1982
|
+
borrowIncentiveCoinNames = borrowIncentiveCoinNames || [
|
|
1983
|
+
...SUPPORT_BORROW_INCENTIVE_POOLS
|
|
1984
|
+
];
|
|
1985
|
+
const queryPkgId = query.address.get("borrowIncentive.query");
|
|
1986
|
+
const incentiveAccountsId = query.address.get(
|
|
1987
|
+
"borrowIncentive.incentiveAccounts"
|
|
1988
|
+
);
|
|
1989
|
+
const queryTarget = `${queryPkgId}::incentive_account_query::incentive_account_data`;
|
|
1990
|
+
const txBlock = new SuiKitTxBlock2();
|
|
1991
|
+
txBlock.moveCall(queryTarget, [incentiveAccountsId, obligationId]);
|
|
1992
|
+
const queryResult = await query.suiKit.inspectTxn(txBlock);
|
|
1993
|
+
const borrowIncentiveAccountsQueryData = queryResult.events[0].parsedJson;
|
|
1994
|
+
const borrowIncentiveAccounts = Object.values(
|
|
1995
|
+
borrowIncentiveAccountsQueryData.incentive_states
|
|
1996
|
+
).reduce((accounts, accountData) => {
|
|
1997
|
+
const parsedBorrowIncentiveAccount = parseOriginBorrowIncentiveAccountData(accountData);
|
|
1998
|
+
const poolType = parsedBorrowIncentiveAccount.poolType;
|
|
1999
|
+
const coinName = query.utils.parseCoinNameFromType(poolType);
|
|
2000
|
+
if (borrowIncentiveCoinNames && borrowIncentiveCoinNames.includes(coinName)) {
|
|
2001
|
+
accounts[coinName] = {
|
|
2002
|
+
poolType,
|
|
2003
|
+
amount: parsedBorrowIncentiveAccount.amount,
|
|
2004
|
+
points: parsedBorrowIncentiveAccount.points,
|
|
2005
|
+
totalPoints: parsedBorrowIncentiveAccount.totalPoints,
|
|
2006
|
+
index: parsedBorrowIncentiveAccount.index
|
|
2007
|
+
};
|
|
2008
|
+
}
|
|
2009
|
+
return accounts;
|
|
2010
|
+
}, {});
|
|
2011
|
+
return borrowIncentiveAccounts;
|
|
1736
2012
|
};
|
|
1737
2013
|
|
|
1738
2014
|
// src/queries/priceQuery.ts
|
|
@@ -2364,38 +2640,60 @@ var ScallopQuery = class {
|
|
|
2364
2640
|
return await getStakePool(this, stakeMarketCoinName);
|
|
2365
2641
|
}
|
|
2366
2642
|
/**
|
|
2367
|
-
* Get reward pools data.
|
|
2643
|
+
* Get stake reward pools data.
|
|
2368
2644
|
*
|
|
2369
2645
|
* @description
|
|
2370
2646
|
* For backward compatible, it is recommended to use `getSpools` method
|
|
2371
2647
|
* to get all spools data.
|
|
2372
2648
|
*
|
|
2373
2649
|
* @param stakeMarketCoinNames - Specific an array of stake market coin name.
|
|
2374
|
-
* @return
|
|
2650
|
+
* @return Stake reward pools data.
|
|
2375
2651
|
*/
|
|
2376
|
-
async
|
|
2652
|
+
async getStakeRewardPools(stakeMarketCoinNames) {
|
|
2377
2653
|
stakeMarketCoinNames = stakeMarketCoinNames ?? [...SUPPORT_SPOOLS];
|
|
2378
|
-
const
|
|
2654
|
+
const stakeRewardPools = {};
|
|
2379
2655
|
for (const stakeMarketCoinName of stakeMarketCoinNames) {
|
|
2380
|
-
const
|
|
2381
|
-
|
|
2382
|
-
|
|
2656
|
+
const stakeRewardPool = await getStakeRewardPool(
|
|
2657
|
+
this,
|
|
2658
|
+
stakeMarketCoinName
|
|
2659
|
+
);
|
|
2660
|
+
if (stakeRewardPool) {
|
|
2661
|
+
stakeRewardPools[stakeMarketCoinName] = stakeRewardPool;
|
|
2383
2662
|
}
|
|
2384
2663
|
}
|
|
2385
|
-
return
|
|
2664
|
+
return stakeRewardPools;
|
|
2386
2665
|
}
|
|
2387
2666
|
/**
|
|
2388
|
-
* Get reward pool data.
|
|
2667
|
+
* Get stake reward pool data.
|
|
2389
2668
|
*
|
|
2390
2669
|
* @description
|
|
2391
2670
|
* For backward compatible, it is recommended to use `getSpool` method
|
|
2392
2671
|
* to get spool data.
|
|
2393
2672
|
*
|
|
2394
2673
|
* @param marketCoinName - Specific support stake market coin name.
|
|
2395
|
-
* @return
|
|
2674
|
+
* @return Stake reward pool data.
|
|
2396
2675
|
*/
|
|
2397
|
-
async
|
|
2398
|
-
return await
|
|
2676
|
+
async getStakeRewardPool(stakeMarketCoinName) {
|
|
2677
|
+
return await getStakeRewardPool(this, stakeMarketCoinName);
|
|
2678
|
+
}
|
|
2679
|
+
/**
|
|
2680
|
+
* Get borrow incentive pools data.
|
|
2681
|
+
*
|
|
2682
|
+
* @param coinNames - Specific an array of support borrow incentive coin name.
|
|
2683
|
+
* @return Borrow incentive pools data.
|
|
2684
|
+
*/
|
|
2685
|
+
async getBorrowIncentivePools(coinNames) {
|
|
2686
|
+
return await queryBorrowIncentivePools(this, coinNames);
|
|
2687
|
+
}
|
|
2688
|
+
/**
|
|
2689
|
+
* Get borrow incentive accounts data.
|
|
2690
|
+
*
|
|
2691
|
+
* @param coinNames - Specific support borrow incentive coin name.
|
|
2692
|
+
* @param ownerAddress - The owner address.
|
|
2693
|
+
* @return Borrow incentive accounts data.
|
|
2694
|
+
*/
|
|
2695
|
+
async getBorrowIncentiveAccounts(obligationId, coinNames) {
|
|
2696
|
+
return await queryBorrowIncentiveAccounts(this, obligationId, coinNames);
|
|
2399
2697
|
}
|
|
2400
2698
|
/**
|
|
2401
2699
|
* Get user lending and spool infomation for specific pools.
|
|
@@ -2459,13 +2757,22 @@ var ScallopUtils = class {
|
|
|
2459
2757
|
constructor(params, instance) {
|
|
2460
2758
|
this._priceMap = /* @__PURE__ */ new Map();
|
|
2461
2759
|
/**
|
|
2462
|
-
* Get reward type of
|
|
2760
|
+
* Get reward type of spool.
|
|
2463
2761
|
*
|
|
2464
2762
|
* @param stakeMarketCoinName - Support stake market coin.
|
|
2465
|
-
* @return
|
|
2763
|
+
* @return Spool reward coin name.
|
|
2466
2764
|
*/
|
|
2467
|
-
this.
|
|
2468
|
-
return
|
|
2765
|
+
this.getSpoolRewardCoinName = (stakeMarketCoinName) => {
|
|
2766
|
+
return spoolRewardCoins[stakeMarketCoinName];
|
|
2767
|
+
};
|
|
2768
|
+
/**
|
|
2769
|
+
* Get reward type of borrow incentive pool.
|
|
2770
|
+
*
|
|
2771
|
+
* @param borrowIncentiveCoinName - Support borrow incentive coin.
|
|
2772
|
+
* @return Borrow incentive reward coin name.
|
|
2773
|
+
*/
|
|
2774
|
+
this.getBorrowIncentiveRewardCoinName = (borrowIncentiveCoinName) => {
|
|
2775
|
+
return borrowIncentiveRewardCoins[borrowIncentiveCoinName];
|
|
2469
2776
|
};
|
|
2470
2777
|
this.params = params;
|
|
2471
2778
|
this._suiKit = instance?.suiKit ?? new SuiKit2(params);
|
|
@@ -2522,7 +2829,7 @@ var ScallopUtils = class {
|
|
|
2522
2829
|
throw Error(`Coin ${coinName} is not supported`);
|
|
2523
2830
|
}
|
|
2524
2831
|
if (coinName === "sui")
|
|
2525
|
-
return
|
|
2832
|
+
return normalizeStructTag3(`${coinPackageId}::sui::SUI`);
|
|
2526
2833
|
const wormHolePckageIds = [
|
|
2527
2834
|
this._address.get("core.coins.usdc.id") ?? wormholeCoinIds.usdc,
|
|
2528
2835
|
this._address.get("core.coins.usdt.id") ?? wormholeCoinIds.usdt,
|
|
@@ -2554,7 +2861,7 @@ var ScallopUtils = class {
|
|
|
2554
2861
|
return `${PROTOCOL_OBJECT_ID}::reserve::MarketCoin<${coinType}>`;
|
|
2555
2862
|
}
|
|
2556
2863
|
parseCoinNameFromType(coinType) {
|
|
2557
|
-
coinType =
|
|
2864
|
+
coinType = normalizeStructTag3(coinType);
|
|
2558
2865
|
const coinTypeRegex = new RegExp(`((0x[^:]+::[^:]+::[^<>]+))(?![^<>]*<)`);
|
|
2559
2866
|
const coinTypeMatch = coinType.match(coinTypeRegex);
|
|
2560
2867
|
const isMarketCoinType = coinType.includes("reserve::MarketCoin");
|
|
@@ -2744,7 +3051,7 @@ import { SuiKit as SuiKit3 } from "@scallop-io/sui-kit";
|
|
|
2744
3051
|
// src/builders/coreBuilder.ts
|
|
2745
3052
|
import { TransactionBlock } from "@mysten/sui.js/transactions";
|
|
2746
3053
|
import { SUI_CLOCK_OBJECT_ID as SUI_CLOCK_OBJECT_ID2 } from "@mysten/sui.js/utils";
|
|
2747
|
-
import { SuiTxBlock as
|
|
3054
|
+
import { SuiTxBlock as SuiKitTxBlock3 } from "@scallop-io/sui-kit";
|
|
2748
3055
|
|
|
2749
3056
|
// src/builders/oracle.ts
|
|
2750
3057
|
import { SUI_CLOCK_OBJECT_ID } from "@mysten/sui.js/utils";
|
|
@@ -2882,13 +3189,6 @@ var updatePythPrice = (txBlock, packageId, request, stateId, feedObjectId, regis
|
|
|
2882
3189
|
};
|
|
2883
3190
|
|
|
2884
3191
|
// src/builders/coreBuilder.ts
|
|
2885
|
-
var requireSender = (txBlock) => {
|
|
2886
|
-
const sender = txBlock.blockData.sender;
|
|
2887
|
-
if (!sender) {
|
|
2888
|
-
throw new Error("Sender is required");
|
|
2889
|
-
}
|
|
2890
|
-
return sender;
|
|
2891
|
-
};
|
|
2892
3192
|
var requireObligationInfo = async (...params) => {
|
|
2893
3193
|
const [builder, txBlock, obligationId, obligationKey] = params;
|
|
2894
3194
|
if (params.length === 3 && obligationId)
|
|
@@ -3178,7 +3478,7 @@ var generateCoreQuickMethod = ({
|
|
|
3178
3478
|
};
|
|
3179
3479
|
};
|
|
3180
3480
|
var newCoreTxBlock = (builder, initTxBlock) => {
|
|
3181
|
-
const txBlock = initTxBlock instanceof TransactionBlock ? new
|
|
3481
|
+
const txBlock = initTxBlock instanceof TransactionBlock ? new SuiKitTxBlock3(initTxBlock) : initTxBlock ? initTxBlock : new SuiKitTxBlock3();
|
|
3182
3482
|
const normalMethod = generateCoreNormalMethod({
|
|
3183
3483
|
builder,
|
|
3184
3484
|
txBlock
|
|
@@ -3208,19 +3508,12 @@ var newCoreTxBlock = (builder, initTxBlock) => {
|
|
|
3208
3508
|
// src/builders/spoolBuilder.ts
|
|
3209
3509
|
import { TransactionBlock as TransactionBlock2 } from "@mysten/sui.js/transactions";
|
|
3210
3510
|
import { SUI_CLOCK_OBJECT_ID as SUI_CLOCK_OBJECT_ID3 } from "@mysten/sui.js/utils";
|
|
3211
|
-
import { SuiTxBlock as
|
|
3212
|
-
var requireSender2 = (txBlock) => {
|
|
3213
|
-
const sender = txBlock.blockData.sender;
|
|
3214
|
-
if (!sender) {
|
|
3215
|
-
throw new Error("Sender is required");
|
|
3216
|
-
}
|
|
3217
|
-
return sender;
|
|
3218
|
-
};
|
|
3511
|
+
import { SuiTxBlock as SuiKitTxBlock4 } from "@scallop-io/sui-kit";
|
|
3219
3512
|
var requireStakeAccountIds = async (...params) => {
|
|
3220
3513
|
const [builder, txBlock, stakeMarketCoinName, stakeAccountId] = params;
|
|
3221
3514
|
if (params.length === 4 && stakeAccountId)
|
|
3222
3515
|
return [stakeAccountId];
|
|
3223
|
-
const sender =
|
|
3516
|
+
const sender = requireSender(txBlock);
|
|
3224
3517
|
const stakeAccounts = await getStakeAccounts(builder.query, sender);
|
|
3225
3518
|
if (stakeAccounts[stakeMarketCoinName].length === 0) {
|
|
3226
3519
|
throw new Error(`No stake account id found for sender ${sender}`);
|
|
@@ -3229,7 +3522,7 @@ var requireStakeAccountIds = async (...params) => {
|
|
|
3229
3522
|
};
|
|
3230
3523
|
var requireStakeAccounts = async (...params) => {
|
|
3231
3524
|
const [builder, txBlock, stakeMarketCoinName, stakeAccountId] = params;
|
|
3232
|
-
const sender =
|
|
3525
|
+
const sender = requireSender(txBlock);
|
|
3233
3526
|
const stakeAccounts = await getStakeAccounts(builder.query, sender);
|
|
3234
3527
|
if (stakeAccounts[stakeMarketCoinName].length === 0) {
|
|
3235
3528
|
throw new Error(`No stake account found for sender ${sender}`);
|
|
@@ -3288,7 +3581,7 @@ var generateSpoolNormalMethod = ({
|
|
|
3288
3581
|
`spool.pools.${stakeMarketCoinName}.rewardPoolId`
|
|
3289
3582
|
);
|
|
3290
3583
|
const marketCoinType = builder.utils.parseMarketCoinType(stakeMarketCoinName);
|
|
3291
|
-
const rewardCoinName =
|
|
3584
|
+
const rewardCoinName = spoolRewardCoins[stakeMarketCoinName];
|
|
3292
3585
|
const rewardCoinType = builder.utils.parseCoinType(rewardCoinName);
|
|
3293
3586
|
return txBlock.moveCall(
|
|
3294
3587
|
`${spoolIds.spoolPkg}::user::redeem_rewards`,
|
|
@@ -3304,7 +3597,7 @@ var generateSpoolQuickMethod = ({
|
|
|
3304
3597
|
}) => {
|
|
3305
3598
|
return {
|
|
3306
3599
|
stakeQuick: async (amountOrMarketCoin, stakeMarketCoinName, stakeAccountId) => {
|
|
3307
|
-
const sender =
|
|
3600
|
+
const sender = requireSender(txBlock);
|
|
3308
3601
|
const stakeAccountIds = await requireStakeAccountIds(
|
|
3309
3602
|
builder,
|
|
3310
3603
|
txBlock,
|
|
@@ -3363,17 +3656,17 @@ var generateSpoolQuickMethod = ({
|
|
|
3363
3656
|
stakeMarketCoinName,
|
|
3364
3657
|
stakeAccountId
|
|
3365
3658
|
);
|
|
3366
|
-
const
|
|
3659
|
+
const rewardCoins = [];
|
|
3367
3660
|
for (const accountId of stakeAccountIds) {
|
|
3368
3661
|
const rewardCoin = txBlock.claim(accountId, stakeMarketCoinName);
|
|
3369
|
-
|
|
3662
|
+
rewardCoins.push(rewardCoin);
|
|
3370
3663
|
}
|
|
3371
|
-
return
|
|
3664
|
+
return rewardCoins;
|
|
3372
3665
|
}
|
|
3373
3666
|
};
|
|
3374
3667
|
};
|
|
3375
3668
|
var newSpoolTxBlock = (builder, initTxBlock) => {
|
|
3376
|
-
const txBlock = initTxBlock instanceof TransactionBlock2 ? new
|
|
3669
|
+
const txBlock = initTxBlock instanceof TransactionBlock2 ? new SuiKitTxBlock4(initTxBlock) : initTxBlock ? initTxBlock : new SuiKitTxBlock4();
|
|
3377
3670
|
const normalMethod = generateSpoolNormalMethod({
|
|
3378
3671
|
builder,
|
|
3379
3672
|
txBlock
|
|
@@ -3400,13 +3693,183 @@ var newSpoolTxBlock = (builder, initTxBlock) => {
|
|
|
3400
3693
|
});
|
|
3401
3694
|
};
|
|
3402
3695
|
|
|
3696
|
+
// src/builders/borrowIncentiveBuilder.ts
|
|
3697
|
+
import { TransactionBlock as TransactionBlock3 } from "@mysten/sui.js/transactions";
|
|
3698
|
+
import { SUI_CLOCK_OBJECT_ID as SUI_CLOCK_OBJECT_ID4 } from "@mysten/sui.js/utils";
|
|
3699
|
+
import { SuiTxBlock as SuiKitTxBlock5 } from "@scallop-io/sui-kit";
|
|
3700
|
+
var requireObligationInfo2 = async (...params) => {
|
|
3701
|
+
const [builder, txBlock, obligationId, obligationKey] = params;
|
|
3702
|
+
if (params.length === 4 && obligationId && obligationKey && typeof obligationId === "string") {
|
|
3703
|
+
const obligationLocked = await getObligationLocked(
|
|
3704
|
+
builder.query,
|
|
3705
|
+
obligationId
|
|
3706
|
+
);
|
|
3707
|
+
return { obligationId, obligationKey, obligationLocked };
|
|
3708
|
+
}
|
|
3709
|
+
const sender = requireSender(txBlock);
|
|
3710
|
+
const obligations = await getObligations(builder.query, sender);
|
|
3711
|
+
if (obligations.length === 0) {
|
|
3712
|
+
throw new Error(`No obligation found for sender ${sender}`);
|
|
3713
|
+
}
|
|
3714
|
+
return {
|
|
3715
|
+
obligationId: obligations[0].id,
|
|
3716
|
+
obligationKey: obligations[0].keyId,
|
|
3717
|
+
obligationLocked: obligations[0].locked
|
|
3718
|
+
};
|
|
3719
|
+
};
|
|
3720
|
+
var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
|
|
3721
|
+
const borrowIncentiveIds = {
|
|
3722
|
+
borrowIncentivePkg: builder.address.get("borrowIncentive.id"),
|
|
3723
|
+
query: builder.address.get("borrowIncentive.query"),
|
|
3724
|
+
incentivePools: builder.address.get("borrowIncentive.incentivePools"),
|
|
3725
|
+
incentiveAccounts: builder.address.get(
|
|
3726
|
+
"borrowIncentive.incentiveAccounts"
|
|
3727
|
+
),
|
|
3728
|
+
obligationAccessStore: builder.address.get("core.obligationAccessStore")
|
|
3729
|
+
};
|
|
3730
|
+
return {
|
|
3731
|
+
stakeObligation: (obligationId, obligaionKey, coinName) => {
|
|
3732
|
+
const rewardCoinName = borrowIncentiveRewardCoins[coinName];
|
|
3733
|
+
const rewardType = builder.utils.parseCoinType(rewardCoinName);
|
|
3734
|
+
txBlock.moveCall(
|
|
3735
|
+
`${borrowIncentiveIds.borrowIncentivePkg}::user::stake`,
|
|
3736
|
+
[
|
|
3737
|
+
borrowIncentiveIds.incentivePools,
|
|
3738
|
+
borrowIncentiveIds.incentiveAccounts,
|
|
3739
|
+
obligaionKey,
|
|
3740
|
+
obligationId,
|
|
3741
|
+
borrowIncentiveIds.obligationAccessStore,
|
|
3742
|
+
SUI_CLOCK_OBJECT_ID4
|
|
3743
|
+
],
|
|
3744
|
+
[rewardType]
|
|
3745
|
+
);
|
|
3746
|
+
},
|
|
3747
|
+
unstakeObligation: (obligationId, obligaionKey, coinName) => {
|
|
3748
|
+
const rewardCoinName = borrowIncentiveRewardCoins[coinName];
|
|
3749
|
+
const rewardType = builder.utils.parseCoinType(rewardCoinName);
|
|
3750
|
+
txBlock.moveCall(
|
|
3751
|
+
`${borrowIncentiveIds.borrowIncentivePkg}::user::unstake`,
|
|
3752
|
+
[
|
|
3753
|
+
borrowIncentiveIds.incentivePools,
|
|
3754
|
+
borrowIncentiveIds.incentiveAccounts,
|
|
3755
|
+
obligaionKey,
|
|
3756
|
+
obligationId,
|
|
3757
|
+
SUI_CLOCK_OBJECT_ID4
|
|
3758
|
+
],
|
|
3759
|
+
[rewardType]
|
|
3760
|
+
);
|
|
3761
|
+
},
|
|
3762
|
+
claimBorrowIncentive: (obligationId, obligaionKey, coinName) => {
|
|
3763
|
+
const rewardCoinName = borrowIncentiveRewardCoins[coinName];
|
|
3764
|
+
const rewardType = builder.utils.parseCoinType(rewardCoinName);
|
|
3765
|
+
return txBlock.moveCall(
|
|
3766
|
+
`${borrowIncentiveIds.borrowIncentivePkg}::user::redeem_rewards`,
|
|
3767
|
+
[
|
|
3768
|
+
borrowIncentiveIds.incentivePools,
|
|
3769
|
+
borrowIncentiveIds.incentiveAccounts,
|
|
3770
|
+
obligaionKey,
|
|
3771
|
+
obligationId,
|
|
3772
|
+
SUI_CLOCK_OBJECT_ID4
|
|
3773
|
+
],
|
|
3774
|
+
[rewardType]
|
|
3775
|
+
);
|
|
3776
|
+
}
|
|
3777
|
+
};
|
|
3778
|
+
};
|
|
3779
|
+
var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
|
|
3780
|
+
return {
|
|
3781
|
+
stakeObligationQuick: async (coinName, obligation, obligationKey) => {
|
|
3782
|
+
const {
|
|
3783
|
+
obligationId: obligationArg,
|
|
3784
|
+
obligationKey: obligationtKeyArg,
|
|
3785
|
+
obligationLocked
|
|
3786
|
+
} = await requireObligationInfo2(
|
|
3787
|
+
builder,
|
|
3788
|
+
txBlock,
|
|
3789
|
+
obligation,
|
|
3790
|
+
obligationKey
|
|
3791
|
+
);
|
|
3792
|
+
const unstakeObligationBeforeStake = !!txBlock.txBlock.blockData.transactions.find(
|
|
3793
|
+
(txn) => txn.kind === "MoveCall" && txn.target === `${builder.address.get("borrowIncentive.id")}::user::unstake`
|
|
3794
|
+
);
|
|
3795
|
+
if (!obligationLocked || unstakeObligationBeforeStake) {
|
|
3796
|
+
txBlock.stakeObligation(obligationArg, obligationtKeyArg, coinName);
|
|
3797
|
+
}
|
|
3798
|
+
},
|
|
3799
|
+
unstakeObligationQuick: async (coinName, obligation, obligationKey) => {
|
|
3800
|
+
const {
|
|
3801
|
+
obligationId: obligationArg,
|
|
3802
|
+
obligationKey: obligationtKeyArg,
|
|
3803
|
+
obligationLocked
|
|
3804
|
+
} = await requireObligationInfo2(
|
|
3805
|
+
builder,
|
|
3806
|
+
txBlock,
|
|
3807
|
+
obligation,
|
|
3808
|
+
obligationKey
|
|
3809
|
+
);
|
|
3810
|
+
if (obligationLocked) {
|
|
3811
|
+
txBlock.unstakeObligation(obligationArg, obligationtKeyArg, coinName);
|
|
3812
|
+
}
|
|
3813
|
+
},
|
|
3814
|
+
claimBorrowIncentiveQuick: async (coinName, obligation, obligationKey) => {
|
|
3815
|
+
const {
|
|
3816
|
+
obligationId: obligationArg,
|
|
3817
|
+
obligationKey: obligationtKeyArg
|
|
3818
|
+
} = await requireObligationInfo2(
|
|
3819
|
+
builder,
|
|
3820
|
+
txBlock,
|
|
3821
|
+
obligation,
|
|
3822
|
+
obligationKey
|
|
3823
|
+
);
|
|
3824
|
+
return txBlock.claimBorrowIncentive(
|
|
3825
|
+
obligationArg,
|
|
3826
|
+
obligationtKeyArg,
|
|
3827
|
+
coinName
|
|
3828
|
+
);
|
|
3829
|
+
}
|
|
3830
|
+
};
|
|
3831
|
+
};
|
|
3832
|
+
var newBorrowIncentiveTxBlock = (builder, initTxBlock) => {
|
|
3833
|
+
const txBlock = initTxBlock instanceof TransactionBlock3 ? new SuiKitTxBlock5(initTxBlock) : initTxBlock ? initTxBlock : new SuiKitTxBlock5();
|
|
3834
|
+
const normalMethod = generateBorrowIncentiveNormalMethod({
|
|
3835
|
+
builder,
|
|
3836
|
+
txBlock
|
|
3837
|
+
});
|
|
3838
|
+
const normalTxBlock = new Proxy(txBlock, {
|
|
3839
|
+
get: (target, prop) => {
|
|
3840
|
+
if (prop in normalMethod) {
|
|
3841
|
+
return Reflect.get(normalMethod, prop);
|
|
3842
|
+
}
|
|
3843
|
+
return Reflect.get(target, prop);
|
|
3844
|
+
}
|
|
3845
|
+
});
|
|
3846
|
+
const quickMethod = generateBorrowIncentiveQuickMethod({
|
|
3847
|
+
builder,
|
|
3848
|
+
txBlock: normalTxBlock
|
|
3849
|
+
});
|
|
3850
|
+
return new Proxy(normalTxBlock, {
|
|
3851
|
+
get: (target, prop) => {
|
|
3852
|
+
if (prop in quickMethod) {
|
|
3853
|
+
return Reflect.get(quickMethod, prop);
|
|
3854
|
+
}
|
|
3855
|
+
return Reflect.get(target, prop);
|
|
3856
|
+
}
|
|
3857
|
+
});
|
|
3858
|
+
};
|
|
3859
|
+
|
|
3403
3860
|
// src/builders/index.ts
|
|
3404
3861
|
var newScallopTxBlock = (builder, initTxBlock) => {
|
|
3405
|
-
const
|
|
3862
|
+
const borrowIncentiveTxBlock = newBorrowIncentiveTxBlock(
|
|
3863
|
+
builder,
|
|
3864
|
+
initTxBlock
|
|
3865
|
+
);
|
|
3866
|
+
const spoolTxBlock = newSpoolTxBlock(builder, borrowIncentiveTxBlock);
|
|
3406
3867
|
const coreTxBlock = newCoreTxBlock(builder, spoolTxBlock);
|
|
3407
3868
|
return new Proxy(coreTxBlock, {
|
|
3408
3869
|
get: (target, prop) => {
|
|
3409
|
-
if (prop in
|
|
3870
|
+
if (prop in borrowIncentiveTxBlock) {
|
|
3871
|
+
return Reflect.get(borrowIncentiveTxBlock, prop);
|
|
3872
|
+
} else if (prop in spoolTxBlock) {
|
|
3410
3873
|
return Reflect.get(spoolTxBlock, prop);
|
|
3411
3874
|
}
|
|
3412
3875
|
return Reflect.get(target, prop);
|
|
@@ -3630,8 +4093,8 @@ var ScallopClient = class {
|
|
|
3630
4093
|
* @param stakeMarketCoinName - Support stake market coin.
|
|
3631
4094
|
* @return Reward pool data.
|
|
3632
4095
|
*/
|
|
3633
|
-
async
|
|
3634
|
-
return await this.query.
|
|
4096
|
+
async getStakeRewardPool(stakeMarketCoinName) {
|
|
4097
|
+
return await this.query.getStakeRewardPool(stakeMarketCoinName);
|
|
3635
4098
|
}
|
|
3636
4099
|
async openObligation(sign = true) {
|
|
3637
4100
|
const txBlock = this.builder.createTxBlock();
|
|
@@ -3903,11 +4366,84 @@ var ScallopClient = class {
|
|
|
3903
4366
|
const txBlock = this.builder.createTxBlock();
|
|
3904
4367
|
const sender = walletAddress || this.walletAddress;
|
|
3905
4368
|
txBlock.setSender(sender);
|
|
3906
|
-
const
|
|
4369
|
+
const rewardCoins = await txBlock.claimQuick(
|
|
3907
4370
|
stakeMarketCoinName,
|
|
3908
4371
|
stakeAccountId
|
|
3909
4372
|
);
|
|
3910
|
-
txBlock.transferObjects(
|
|
4373
|
+
txBlock.transferObjects(rewardCoins, sender);
|
|
4374
|
+
if (sign) {
|
|
4375
|
+
return await this.suiKit.signAndSendTxn(
|
|
4376
|
+
txBlock
|
|
4377
|
+
);
|
|
4378
|
+
} else {
|
|
4379
|
+
return txBlock.txBlock;
|
|
4380
|
+
}
|
|
4381
|
+
}
|
|
4382
|
+
/* ==================== Borrow Incentive Method ==================== */
|
|
4383
|
+
/**
|
|
4384
|
+
* stake obligaion.
|
|
4385
|
+
*
|
|
4386
|
+
* @param sign - Decide to directly sign the transaction or return the transaction block.
|
|
4387
|
+
* @param obligaionId - The obligation account object.
|
|
4388
|
+
* @param obligaionKeyId - The obligation key account object.
|
|
4389
|
+
* @param walletAddress - The wallet address of the owner.
|
|
4390
|
+
* @return Transaction block response or transaction block
|
|
4391
|
+
*/
|
|
4392
|
+
async stakeObligation(coinName, obligaionId, obligaionKeyId, sign = true, walletAddress) {
|
|
4393
|
+
const txBlock = this.builder.createTxBlock();
|
|
4394
|
+
const sender = walletAddress || this.walletAddress;
|
|
4395
|
+
txBlock.setSender(sender);
|
|
4396
|
+
await txBlock.stakeObligationQuick(coinName, obligaionId, obligaionKeyId);
|
|
4397
|
+
if (sign) {
|
|
4398
|
+
return await this.suiKit.signAndSendTxn(
|
|
4399
|
+
txBlock
|
|
4400
|
+
);
|
|
4401
|
+
} else {
|
|
4402
|
+
return txBlock.txBlock;
|
|
4403
|
+
}
|
|
4404
|
+
}
|
|
4405
|
+
/**
|
|
4406
|
+
* unstake obligaion.
|
|
4407
|
+
*
|
|
4408
|
+
* @param sign - Decide to directly sign the transaction or return the transaction block.
|
|
4409
|
+
* @param obligaionId - The obligation account object.
|
|
4410
|
+
* @param obligaionKeyId - The obligation key account object.
|
|
4411
|
+
* @param walletAddress - The wallet address of the owner.
|
|
4412
|
+
* @return Transaction block response or transaction block
|
|
4413
|
+
*/
|
|
4414
|
+
async unstakeObligation(coinName, obligaionId, obligaionKeyId, sign = true, walletAddress) {
|
|
4415
|
+
const txBlock = this.builder.createTxBlock();
|
|
4416
|
+
const sender = walletAddress || this.walletAddress;
|
|
4417
|
+
txBlock.setSender(sender);
|
|
4418
|
+
await txBlock.unstakeObligationQuick(coinName, obligaionId, obligaionKeyId);
|
|
4419
|
+
if (sign) {
|
|
4420
|
+
return await this.suiKit.signAndSendTxn(
|
|
4421
|
+
txBlock
|
|
4422
|
+
);
|
|
4423
|
+
} else {
|
|
4424
|
+
return txBlock.txBlock;
|
|
4425
|
+
}
|
|
4426
|
+
}
|
|
4427
|
+
/**
|
|
4428
|
+
* unstake market coin from the specific spool.
|
|
4429
|
+
*
|
|
4430
|
+
* @param marketCoinName - Types of mak coin.
|
|
4431
|
+
* @param amount - The amount of coins would deposit.
|
|
4432
|
+
* @param sign - Decide to directly sign the transaction or return the transaction block.
|
|
4433
|
+
* @param accountId - The stake account object.
|
|
4434
|
+
* @param walletAddress - The wallet address of the owner.
|
|
4435
|
+
* @return Transaction block response or transaction block
|
|
4436
|
+
*/
|
|
4437
|
+
async claimBorrowIncentive(coinName, obligaionId, obligaionKeyId, sign = true, walletAddress) {
|
|
4438
|
+
const txBlock = this.builder.createTxBlock();
|
|
4439
|
+
const sender = walletAddress || this.walletAddress;
|
|
4440
|
+
txBlock.setSender(sender);
|
|
4441
|
+
const rewardCoin = await txBlock.claimBorrowIncentiveQuick(
|
|
4442
|
+
coinName,
|
|
4443
|
+
obligaionId,
|
|
4444
|
+
obligaionKeyId
|
|
4445
|
+
);
|
|
4446
|
+
txBlock.transferObjects([rewardCoin], sender);
|
|
3911
4447
|
if (sign) {
|
|
3912
4448
|
return await this.suiKit.signAndSendTxn(
|
|
3913
4449
|
txBlock
|
|
@@ -4020,12 +4556,14 @@ export {
|
|
|
4020
4556
|
ADDRESSES_ID,
|
|
4021
4557
|
API_BASE_URL,
|
|
4022
4558
|
PROTOCOL_OBJECT_ID,
|
|
4559
|
+
SUPPORT_BORROW_INCENTIVE_POOLS,
|
|
4560
|
+
SUPPORT_BORROW_INCENTIVE_REWARDS,
|
|
4023
4561
|
SUPPORT_COLLATERALS,
|
|
4024
4562
|
SUPPORT_ORACLES,
|
|
4025
4563
|
SUPPORT_PACKAGES,
|
|
4026
4564
|
SUPPORT_POOLS,
|
|
4027
|
-
SUPPORT_REWARD_POOLS,
|
|
4028
4565
|
SUPPORT_SPOOLS,
|
|
4566
|
+
SUPPORT_SPOOLS_REWARDS,
|
|
4029
4567
|
Scallop,
|
|
4030
4568
|
ScallopAddress,
|
|
4031
4569
|
ScallopBuilder,
|
|
@@ -4033,10 +4571,11 @@ export {
|
|
|
4033
4571
|
ScallopQuery,
|
|
4034
4572
|
ScallopUtils,
|
|
4035
4573
|
assetCoins,
|
|
4574
|
+
borrowIncentiveRewardCoins,
|
|
4036
4575
|
coinDecimals,
|
|
4037
4576
|
coinIds,
|
|
4038
4577
|
marketCoins,
|
|
4039
|
-
|
|
4578
|
+
spoolRewardCoins,
|
|
4040
4579
|
stakeMarketCoins,
|
|
4041
4580
|
voloCoinIds,
|
|
4042
4581
|
wormholeCoinIds
|