@scallop-io/sui-scallop-sdk 0.44.2 → 0.44.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/builders/borrowIncentiveBuilder.d.ts +12 -0
- package/dist/constants/common.d.ts +3 -1
- package/dist/constants/enum.d.ts +3 -2
- package/dist/index.js +815 -228
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +776 -192
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopClient.d.ts +33 -2
- package/dist/models/scallopQuery.d.ts +31 -10
- package/dist/models/scallopUtils.d.ts +11 -4
- package/dist/queries/borrowIncentiveQuery.d.ts +24 -0
- package/dist/queries/coreQuery.d.ts +8 -0
- package/dist/queries/index.d.ts +1 -0
- package/dist/queries/spoolQuery.d.ts +13 -5
- package/dist/types/address.d.ts +8 -0
- package/dist/types/builder/borrowIncentive.d.ts +31 -0
- package/dist/types/builder/index.d.ts +3 -1
- package/dist/types/constant/common.d.ts +5 -3
- package/dist/types/constant/enum.d.ts +6 -3
- package/dist/types/query/borrowIncentive.d.ts +118 -0
- package/dist/types/query/core.d.ts +1 -0
- package/dist/types/query/index.d.ts +1 -0
- package/dist/types/query/portfolio.d.ts +13 -0
- package/dist/types/query/spool.d.ts +12 -13
- package/dist/utils/builder.d.ts +8 -0
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/query.d.ts +33 -10
- package/dist/utils/util.d.ts +13 -0
- package/package.json +1 -1
- package/src/builders/borrowIncentiveBuilder.ts +257 -0
- package/src/builders/coreBuilder.ts +1 -14
- package/src/builders/index.ts +9 -2
- package/src/builders/spoolBuilder.ts +3 -16
- package/src/constants/common.ts +4 -1
- package/src/constants/enum.ts +8 -2
- package/src/models/scallopAddress.ts +8 -0
- package/src/models/scallopClient.ts +104 -2
- package/src/models/scallopQuery.ts +48 -14
- package/src/models/scallopUtils.ts +21 -5
- package/src/queries/borrowIncentiveQuery.ts +167 -0
- package/src/queries/coreQuery.ts +58 -15
- package/src/queries/index.ts +1 -0
- package/src/queries/portfolioQuery.ts +59 -5
- package/src/queries/spoolQuery.ts +87 -71
- package/src/types/address.ts +8 -0
- package/src/types/builder/borrowIncentive.ts +67 -0
- package/src/types/builder/index.ts +5 -1
- package/src/types/builder/spool.ts +0 -1
- package/src/types/constant/common.ts +10 -3
- package/src/types/constant/enum.ts +9 -3
- package/src/types/query/borrowIncentive.ts +150 -0
- package/src/types/query/core.ts +1 -1
- package/src/types/query/index.ts +1 -0
- package/src/types/query/portfolio.ts +16 -0
- package/src/types/query/spool.ts +28 -18
- package/src/utils/builder.ts +15 -0
- package/src/utils/index.ts +1 -1
- package/src/utils/query.ts +279 -72
- package/src/utils/util.ts +36 -2
- package/dist/utils/oracle.d.ts +0 -14
- package/src/utils/oracle.ts +0 -36
package/dist/index.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 normalizeStructTag5 } 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
|
|
|
@@ -642,34 +656,25 @@ import { SuiPriceServiceConnection } from "@pythnetwork/pyth-sui-js";
|
|
|
642
656
|
import { SuiKit } from "@scallop-io/sui-kit";
|
|
643
657
|
|
|
644
658
|
// src/queries/coreQuery.ts
|
|
659
|
+
import { normalizeStructTag as normalizeStructTag2 } from "@mysten/sui.js/utils";
|
|
645
660
|
import { SuiTxBlock as SuiKitTxBlock } from "@scallop-io/sui-kit";
|
|
646
661
|
import BigNumber2 from "bignumber.js";
|
|
647
662
|
|
|
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");
|
|
663
|
+
// src/utils/builder.ts
|
|
664
|
+
var requireSender = (txBlock) => {
|
|
665
|
+
const sender = txBlock.blockData.sender;
|
|
666
|
+
if (!sender) {
|
|
667
|
+
throw new Error("Sender is required");
|
|
665
668
|
}
|
|
669
|
+
return sender;
|
|
666
670
|
};
|
|
667
671
|
|
|
668
672
|
// src/utils/query.ts
|
|
669
673
|
import BigNumber from "bignumber.js";
|
|
674
|
+
import { normalizeStructTag } from "@mysten/sui.js/utils";
|
|
670
675
|
var parseOriginMarketPoolData = (originMarketPoolData) => {
|
|
671
676
|
return {
|
|
672
|
-
coinType:
|
|
677
|
+
coinType: normalizeStructTag(originMarketPoolData.type.name),
|
|
673
678
|
// Parse origin data required for basic calculations.
|
|
674
679
|
maxBorrowRate: Number(originMarketPoolData.maxBorrowRate.value) / 2 ** 32,
|
|
675
680
|
borrowRate: Number(originMarketPoolData.interestRate.value) / 2 ** 32,
|
|
@@ -763,7 +768,7 @@ var calculateMarketPoolData = (utils, parsedMarketPoolData) => {
|
|
|
763
768
|
};
|
|
764
769
|
var parseOriginMarketCollateralData = (originMarketCollateralData) => {
|
|
765
770
|
return {
|
|
766
|
-
coinType:
|
|
771
|
+
coinType: normalizeStructTag(originMarketCollateralData.type.name),
|
|
767
772
|
collateralFactor: Number(originMarketCollateralData.collateralFactor.value) / 2 ** 32,
|
|
768
773
|
liquidationFactor: Number(originMarketCollateralData.liquidationFactor.value) / 2 ** 32,
|
|
769
774
|
liquidationDiscount: Number(originMarketCollateralData.liquidationDiscount.value) / 2 ** 32,
|
|
@@ -793,48 +798,48 @@ var calculateMarketCollateralData = (utils, parsedMarketCollateralData) => {
|
|
|
793
798
|
depositCoin: depositCoin.toNumber()
|
|
794
799
|
};
|
|
795
800
|
};
|
|
796
|
-
var
|
|
801
|
+
var parseOriginSpoolData = (originSpoolData) => {
|
|
797
802
|
return {
|
|
798
|
-
stakeType:
|
|
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(
|
|
803
|
+
stakeType: normalizeStructTag(originSpoolData.stakeType.fields.name),
|
|
804
|
+
maxPoint: Number(originSpoolData.maxDistributedPoint),
|
|
805
|
+
distributedPoint: Number(originSpoolData.distributedPoint),
|
|
806
|
+
pointPerPeriod: Number(originSpoolData.distributedPointPerPeriod),
|
|
807
|
+
period: Number(originSpoolData.pointDistributionTime),
|
|
808
|
+
maxStake: Number(originSpoolData.maxStake),
|
|
809
|
+
staked: Number(originSpoolData.stakes),
|
|
810
|
+
index: Number(originSpoolData.index),
|
|
811
|
+
createdAt: Number(originSpoolData.createdAt),
|
|
812
|
+
lastUpdate: Number(originSpoolData.lastUpdate)
|
|
808
813
|
};
|
|
809
814
|
};
|
|
810
|
-
var
|
|
815
|
+
var calculateSpoolData = (parsedSpoolData, stakeMarketCoinPrice, stakeMarketCoinDecimal) => {
|
|
811
816
|
const baseIndexRate = 1e9;
|
|
812
817
|
const distributedPointPerSec = BigNumber(
|
|
813
|
-
|
|
814
|
-
).dividedBy(
|
|
815
|
-
const pointPerSec = BigNumber(
|
|
816
|
-
|
|
818
|
+
parsedSpoolData.pointPerPeriod
|
|
819
|
+
).dividedBy(parsedSpoolData.period);
|
|
820
|
+
const pointPerSec = BigNumber(parsedSpoolData.pointPerPeriod).dividedBy(
|
|
821
|
+
parsedSpoolData.period
|
|
817
822
|
);
|
|
818
|
-
const remainingPeriod = BigNumber(
|
|
819
|
-
const startDate =
|
|
820
|
-
const endDate = remainingPeriod.plus(
|
|
823
|
+
const remainingPeriod = BigNumber(parsedSpoolData.maxPoint).minus(parsedSpoolData.distributedPoint).dividedBy(pointPerSec);
|
|
824
|
+
const startDate = parsedSpoolData.createdAt;
|
|
825
|
+
const endDate = remainingPeriod.plus(parsedSpoolData.lastUpdate).integerValue().toNumber();
|
|
821
826
|
const timeDelta = BigNumber(
|
|
822
|
-
Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) -
|
|
823
|
-
).dividedBy(
|
|
824
|
-
const remainingPoints = BigNumber(
|
|
825
|
-
|
|
827
|
+
Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) - parsedSpoolData.lastUpdate
|
|
828
|
+
).dividedBy(parsedSpoolData.period).toFixed(0);
|
|
829
|
+
const remainingPoints = BigNumber(parsedSpoolData.maxPoint).minus(
|
|
830
|
+
parsedSpoolData.distributedPoint
|
|
826
831
|
);
|
|
827
832
|
const accumulatedPoints = BigNumber.minimum(
|
|
828
|
-
BigNumber(timeDelta).multipliedBy(
|
|
833
|
+
BigNumber(timeDelta).multipliedBy(parsedSpoolData.pointPerPeriod),
|
|
829
834
|
remainingPoints
|
|
830
835
|
);
|
|
831
|
-
const currentPointIndex = BigNumber(
|
|
832
|
-
accumulatedPoints.dividedBy(
|
|
836
|
+
const currentPointIndex = BigNumber(parsedSpoolData.index).plus(
|
|
837
|
+
accumulatedPoints.dividedBy(parsedSpoolData.staked).isFinite() ? BigNumber(baseIndexRate).multipliedBy(accumulatedPoints).dividedBy(parsedSpoolData.staked) : 0
|
|
833
838
|
);
|
|
834
839
|
const currentTotalDistributedPoint = BigNumber(
|
|
835
|
-
|
|
840
|
+
parsedSpoolData.distributedPoint
|
|
836
841
|
).plus(accumulatedPoints);
|
|
837
|
-
const stakedAmount = BigNumber(
|
|
842
|
+
const stakedAmount = BigNumber(parsedSpoolData.staked);
|
|
838
843
|
const stakedCoin = stakedAmount.shiftedBy(-1 * stakeMarketCoinDecimal);
|
|
839
844
|
const stakedValue = stakedCoin.multipliedBy(stakeMarketCoinPrice);
|
|
840
845
|
return {
|
|
@@ -849,35 +854,39 @@ var calculateStakePoolData = (parsedStakePoolData, stakeMarketCoinPrice, stakeMa
|
|
|
849
854
|
stakedValue: stakedValue.toNumber()
|
|
850
855
|
};
|
|
851
856
|
};
|
|
852
|
-
var
|
|
857
|
+
var parseOriginSpoolRewardPoolData = (originSpoolRewardPoolData) => {
|
|
853
858
|
return {
|
|
854
|
-
claimedRewards: Number(
|
|
855
|
-
exchangeRateNumerator: Number(
|
|
859
|
+
claimedRewards: Number(originSpoolRewardPoolData.claimed_rewards),
|
|
860
|
+
exchangeRateNumerator: Number(
|
|
861
|
+
originSpoolRewardPoolData.exchange_rate_numerator
|
|
862
|
+
),
|
|
856
863
|
exchangeRateDenominator: Number(
|
|
857
|
-
|
|
864
|
+
originSpoolRewardPoolData.exchange_rate_denominator
|
|
858
865
|
),
|
|
859
|
-
rewards: Number(
|
|
860
|
-
spoolId: String(
|
|
866
|
+
rewards: Number(originSpoolRewardPoolData.rewards),
|
|
867
|
+
spoolId: String(originSpoolRewardPoolData.spool_id)
|
|
861
868
|
};
|
|
862
869
|
};
|
|
863
|
-
var
|
|
870
|
+
var calculateSpoolRewardPoolData = (parsedSpoolData, parsedSpoolRewardPoolData, calculatedSpoolData, rewardCoinPrice, rewardCoinDecimal) => {
|
|
864
871
|
const rateYearFactor = 365 * 24 * 60 * 60;
|
|
865
|
-
const rewardPerSec = BigNumber(
|
|
866
|
-
const totalRewardAmount = BigNumber(
|
|
872
|
+
const rewardPerSec = BigNumber(calculatedSpoolData.distributedPointPerSec).multipliedBy(parsedSpoolRewardPoolData.exchangeRateNumerator).dividedBy(parsedSpoolRewardPoolData.exchangeRateDenominator);
|
|
873
|
+
const totalRewardAmount = BigNumber(parsedSpoolData.maxPoint).multipliedBy(parsedSpoolRewardPoolData.exchangeRateNumerator).dividedBy(parsedSpoolRewardPoolData.exchangeRateDenominator);
|
|
867
874
|
const totalRewardCoin = totalRewardAmount.shiftedBy(-1 * rewardCoinDecimal);
|
|
868
875
|
const totalRewardValue = totalRewardCoin.multipliedBy(rewardCoinPrice);
|
|
869
|
-
const remaindRewardAmount = BigNumber(
|
|
876
|
+
const remaindRewardAmount = BigNumber(parsedSpoolRewardPoolData.rewards);
|
|
870
877
|
const remaindRewardCoin = remaindRewardAmount.shiftedBy(
|
|
871
878
|
-1 * rewardCoinDecimal
|
|
872
879
|
);
|
|
873
880
|
const remaindRewardValue = remaindRewardCoin.multipliedBy(rewardCoinPrice);
|
|
874
|
-
const claimedRewardAmount = BigNumber(
|
|
881
|
+
const claimedRewardAmount = BigNumber(
|
|
882
|
+
parsedSpoolRewardPoolData.claimedRewards
|
|
883
|
+
);
|
|
875
884
|
const claimedRewardCoin = claimedRewardAmount.shiftedBy(
|
|
876
885
|
-1 * rewardCoinDecimal
|
|
877
886
|
);
|
|
878
887
|
const claimedRewardValue = claimedRewardCoin.multipliedBy(rewardCoinPrice);
|
|
879
888
|
const rewardValueForYear = BigNumber(rewardPerSec).shiftedBy(-1 * rewardCoinDecimal).multipliedBy(rateYearFactor).multipliedBy(rewardCoinPrice);
|
|
880
|
-
const rewardRate = rewardValueForYear.dividedBy(
|
|
889
|
+
const rewardRate = rewardValueForYear.dividedBy(calculatedSpoolData.stakedValue).isFinite() ? rewardValueForYear.dividedBy(calculatedSpoolData.stakedValue).toNumber() : Infinity;
|
|
881
890
|
return {
|
|
882
891
|
rewardApr: rewardRate,
|
|
883
892
|
totalRewardAmount: totalRewardAmount.toNumber(),
|
|
@@ -889,9 +898,133 @@ var calculateRewardPoolData = (parsedStakePoolData, parsedRewardPoolData, calcul
|
|
|
889
898
|
claimedRewardAmount: claimedRewardAmount.toNumber(),
|
|
890
899
|
claimedRewardCoin: claimedRewardCoin.toNumber(),
|
|
891
900
|
claimedRewardValue: claimedRewardValue.toNumber(),
|
|
892
|
-
rewardPerSec: rewardPerSec.toNumber()
|
|
893
|
-
|
|
894
|
-
|
|
901
|
+
rewardPerSec: rewardPerSec.toNumber()
|
|
902
|
+
};
|
|
903
|
+
};
|
|
904
|
+
var parseOriginBorrowIncentivePoolData = (originBorrowIncentivePoolData) => {
|
|
905
|
+
return {
|
|
906
|
+
poolType: normalizeStructTag(originBorrowIncentivePoolData.pool_type.name),
|
|
907
|
+
maxPoint: Number(originBorrowIncentivePoolData.max_distributed_point),
|
|
908
|
+
distributedPoint: Number(originBorrowIncentivePoolData.distributed_point),
|
|
909
|
+
pointPerPeriod: Number(
|
|
910
|
+
originBorrowIncentivePoolData.distributed_point_per_period
|
|
911
|
+
),
|
|
912
|
+
period: Number(originBorrowIncentivePoolData.point_distribution_time),
|
|
913
|
+
maxStake: Number(originBorrowIncentivePoolData.max_stakes),
|
|
914
|
+
staked: Number(originBorrowIncentivePoolData.stakes),
|
|
915
|
+
index: Number(originBorrowIncentivePoolData.index),
|
|
916
|
+
createdAt: Number(originBorrowIncentivePoolData.created_at),
|
|
917
|
+
lastUpdate: Number(originBorrowIncentivePoolData.last_update)
|
|
918
|
+
};
|
|
919
|
+
};
|
|
920
|
+
var calculateBorrowIncentivePoolData = (parsedBorrowIncentivePoolData, borrowIncentiveCoinPrice, borrowIncentiveCoinDecimal) => {
|
|
921
|
+
const baseIndexRate = 1e9;
|
|
922
|
+
const distributedPointPerSec = BigNumber(
|
|
923
|
+
parsedBorrowIncentivePoolData.pointPerPeriod
|
|
924
|
+
).dividedBy(parsedBorrowIncentivePoolData.period);
|
|
925
|
+
const pointPerSec = BigNumber(
|
|
926
|
+
parsedBorrowIncentivePoolData.pointPerPeriod
|
|
927
|
+
).dividedBy(parsedBorrowIncentivePoolData.period);
|
|
928
|
+
const remainingPeriod = BigNumber(parsedBorrowIncentivePoolData.maxPoint).minus(parsedBorrowIncentivePoolData.distributedPoint).dividedBy(pointPerSec);
|
|
929
|
+
const startDate = parsedBorrowIncentivePoolData.createdAt;
|
|
930
|
+
const endDate = remainingPeriod.plus(parsedBorrowIncentivePoolData.lastUpdate).integerValue().toNumber();
|
|
931
|
+
const timeDelta = BigNumber(
|
|
932
|
+
Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) - parsedBorrowIncentivePoolData.lastUpdate
|
|
933
|
+
).dividedBy(parsedBorrowIncentivePoolData.period).toFixed(0);
|
|
934
|
+
const remainingPoints = BigNumber(
|
|
935
|
+
parsedBorrowIncentivePoolData.maxPoint
|
|
936
|
+
).minus(parsedBorrowIncentivePoolData.distributedPoint);
|
|
937
|
+
const accumulatedPoints = BigNumber.minimum(
|
|
938
|
+
BigNumber(timeDelta).multipliedBy(
|
|
939
|
+
parsedBorrowIncentivePoolData.pointPerPeriod
|
|
940
|
+
),
|
|
941
|
+
remainingPoints
|
|
942
|
+
);
|
|
943
|
+
const currentPointIndex = BigNumber(parsedBorrowIncentivePoolData.index).plus(
|
|
944
|
+
accumulatedPoints.dividedBy(parsedBorrowIncentivePoolData.staked).isFinite() ? BigNumber(baseIndexRate).multipliedBy(accumulatedPoints).dividedBy(parsedBorrowIncentivePoolData.staked) : 0
|
|
945
|
+
);
|
|
946
|
+
const currentTotalDistributedPoint = BigNumber(
|
|
947
|
+
parsedBorrowIncentivePoolData.distributedPoint
|
|
948
|
+
).plus(accumulatedPoints);
|
|
949
|
+
const stakedAmount = BigNumber(parsedBorrowIncentivePoolData.staked);
|
|
950
|
+
const stakedCoin = stakedAmount.shiftedBy(-1 * borrowIncentiveCoinDecimal);
|
|
951
|
+
const stakedValue = stakedCoin.multipliedBy(borrowIncentiveCoinPrice);
|
|
952
|
+
return {
|
|
953
|
+
distributedPointPerSec: distributedPointPerSec.toNumber(),
|
|
954
|
+
accumulatedPoints: accumulatedPoints.toNumber(),
|
|
955
|
+
currentPointIndex: currentPointIndex.toNumber(),
|
|
956
|
+
currentTotalDistributedPoint: currentTotalDistributedPoint.toNumber(),
|
|
957
|
+
startDate: new Date(startDate * 1e3),
|
|
958
|
+
endDate: new Date(endDate * 1e3),
|
|
959
|
+
stakedAmount: stakedAmount.toNumber(),
|
|
960
|
+
stakedCoin: stakedCoin.toNumber(),
|
|
961
|
+
stakedValue: stakedValue.toNumber()
|
|
962
|
+
};
|
|
963
|
+
};
|
|
964
|
+
var parseOriginBorrowIncentiveRewardPoolData = (originBorrowIncentiveRewardPoolData) => {
|
|
965
|
+
return {
|
|
966
|
+
rewardType: normalizeStructTag(
|
|
967
|
+
originBorrowIncentiveRewardPoolData.reward_type.name
|
|
968
|
+
),
|
|
969
|
+
claimedRewards: Number(originBorrowIncentiveRewardPoolData.claimed_rewards),
|
|
970
|
+
exchangeRateNumerator: Number(
|
|
971
|
+
originBorrowIncentiveRewardPoolData.exchange_rate_numerator
|
|
972
|
+
),
|
|
973
|
+
exchangeRateDenominator: Number(
|
|
974
|
+
originBorrowIncentiveRewardPoolData.exchange_rate_denominator
|
|
975
|
+
),
|
|
976
|
+
remainingRewards: Number(
|
|
977
|
+
originBorrowIncentiveRewardPoolData.remaining_reward
|
|
978
|
+
)
|
|
979
|
+
};
|
|
980
|
+
};
|
|
981
|
+
var calculateBorrowIncentiveRewardPoolData = (parsedBorrowIncentivePoolData, parsedBorrowIncentiveRewardPoolData, calculatedBorrowIncentivePoolData, rewardCoinPrice, rewardCoinDecimal) => {
|
|
982
|
+
const rateYearFactor = 365 * 24 * 60 * 60;
|
|
983
|
+
const rewardPerSec = BigNumber(
|
|
984
|
+
calculatedBorrowIncentivePoolData.distributedPointPerSec
|
|
985
|
+
).multipliedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateNumerator).dividedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateDenominator);
|
|
986
|
+
const totalRewardAmount = BigNumber(parsedBorrowIncentivePoolData.maxPoint).multipliedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateNumerator).dividedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateDenominator);
|
|
987
|
+
const totalRewardCoin = totalRewardAmount.shiftedBy(-1 * rewardCoinDecimal);
|
|
988
|
+
const totalRewardValue = totalRewardCoin.multipliedBy(rewardCoinPrice);
|
|
989
|
+
const remaindRewardAmount = BigNumber(
|
|
990
|
+
parsedBorrowIncentiveRewardPoolData.remainingRewards
|
|
991
|
+
);
|
|
992
|
+
const remaindRewardCoin = remaindRewardAmount.shiftedBy(
|
|
993
|
+
-1 * rewardCoinDecimal
|
|
994
|
+
);
|
|
995
|
+
const remaindRewardValue = remaindRewardCoin.multipliedBy(rewardCoinPrice);
|
|
996
|
+
const claimedRewardAmount = BigNumber(
|
|
997
|
+
parsedBorrowIncentiveRewardPoolData.claimedRewards
|
|
998
|
+
);
|
|
999
|
+
const claimedRewardCoin = claimedRewardAmount.shiftedBy(
|
|
1000
|
+
-1 * rewardCoinDecimal
|
|
1001
|
+
);
|
|
1002
|
+
const claimedRewardValue = claimedRewardCoin.multipliedBy(rewardCoinPrice);
|
|
1003
|
+
const rewardValueForYear = BigNumber(rewardPerSec).shiftedBy(-1 * rewardCoinDecimal).multipliedBy(rateYearFactor).multipliedBy(rewardCoinPrice);
|
|
1004
|
+
const rewardRate = rewardValueForYear.dividedBy(calculatedBorrowIncentivePoolData.stakedValue).isFinite() ? rewardValueForYear.dividedBy(calculatedBorrowIncentivePoolData.stakedValue).toNumber() : Infinity;
|
|
1005
|
+
return {
|
|
1006
|
+
rewardApr: rewardRate,
|
|
1007
|
+
totalRewardAmount: totalRewardAmount.toNumber(),
|
|
1008
|
+
totalRewardCoin: totalRewardCoin.toNumber(),
|
|
1009
|
+
totalRewardValue: totalRewardValue.toNumber(),
|
|
1010
|
+
remaindRewardAmount: remaindRewardAmount.toNumber(),
|
|
1011
|
+
remaindRewardCoin: remaindRewardCoin.toNumber(),
|
|
1012
|
+
remaindRewardValue: remaindRewardValue.toNumber(),
|
|
1013
|
+
claimedRewardAmount: claimedRewardAmount.toNumber(),
|
|
1014
|
+
claimedRewardCoin: claimedRewardCoin.toNumber(),
|
|
1015
|
+
claimedRewardValue: claimedRewardValue.toNumber(),
|
|
1016
|
+
rewardPerSec: rewardPerSec.toNumber()
|
|
1017
|
+
};
|
|
1018
|
+
};
|
|
1019
|
+
var parseOriginBorrowIncentiveAccountData = (originBorrowIncentiveAccountData) => {
|
|
1020
|
+
return {
|
|
1021
|
+
poolType: normalizeStructTag(
|
|
1022
|
+
originBorrowIncentiveAccountData.pool_type.name
|
|
1023
|
+
),
|
|
1024
|
+
amount: Number(originBorrowIncentiveAccountData.amount),
|
|
1025
|
+
index: Number(originBorrowIncentiveAccountData.index),
|
|
1026
|
+
points: Number(originBorrowIncentiveAccountData.points),
|
|
1027
|
+
totalPoints: Number(originBorrowIncentiveAccountData.total_points)
|
|
895
1028
|
};
|
|
896
1029
|
};
|
|
897
1030
|
var minBigNumber = (...args) => {
|
|
@@ -909,7 +1042,7 @@ var isMarketCoin = (coinName) => {
|
|
|
909
1042
|
.../* @__PURE__ */ new Set([
|
|
910
1043
|
...SUPPORT_POOLS,
|
|
911
1044
|
...SUPPORT_COLLATERALS,
|
|
912
|
-
...
|
|
1045
|
+
...SUPPORT_SPOOLS_REWARDS
|
|
913
1046
|
])
|
|
914
1047
|
].includes(assetCoinName);
|
|
915
1048
|
};
|
|
@@ -925,6 +1058,24 @@ var parseAssetSymbol = (coinName) => {
|
|
|
925
1058
|
return coinName.toUpperCase();
|
|
926
1059
|
}
|
|
927
1060
|
};
|
|
1061
|
+
var parseDataFromPythPriceFeed = (feed, address) => {
|
|
1062
|
+
const assetCoinNames = [
|
|
1063
|
+
.../* @__PURE__ */ new Set([...SUPPORT_POOLS, ...SUPPORT_COLLATERALS])
|
|
1064
|
+
];
|
|
1065
|
+
const assetCoinName = assetCoinNames.find((assetCoinName2) => {
|
|
1066
|
+
return address.get(`core.coins.${assetCoinName2}.oracle.pyth.feed`) === feed.id;
|
|
1067
|
+
});
|
|
1068
|
+
if (assetCoinName) {
|
|
1069
|
+
const price = feed.price.price * 10 ** feed.price.expo;
|
|
1070
|
+
return {
|
|
1071
|
+
coinName: assetCoinName,
|
|
1072
|
+
price,
|
|
1073
|
+
publishTime: Number(feed.price.publishTime) * 10 ** 3
|
|
1074
|
+
};
|
|
1075
|
+
} else {
|
|
1076
|
+
throw new Error("Invalid feed id");
|
|
1077
|
+
}
|
|
1078
|
+
};
|
|
928
1079
|
|
|
929
1080
|
// src/queries/coreQuery.ts
|
|
930
1081
|
var queryMarket = async (query) => {
|
|
@@ -938,6 +1089,12 @@ var queryMarket = async (query) => {
|
|
|
938
1089
|
const pools = {};
|
|
939
1090
|
const collaterals = {};
|
|
940
1091
|
for (const pool of marketData.pools) {
|
|
1092
|
+
const coinType = normalizeStructTag2(pool.type.name);
|
|
1093
|
+
const poolCoinName = query.utils.parseCoinNameFromType(coinType);
|
|
1094
|
+
const coinPrice = (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName] ?? 0;
|
|
1095
|
+
if (!SUPPORT_POOLS.includes(poolCoinName)) {
|
|
1096
|
+
continue;
|
|
1097
|
+
}
|
|
941
1098
|
const parsedMarketPoolData = parseOriginMarketPoolData({
|
|
942
1099
|
type: pool.type,
|
|
943
1100
|
maxBorrowRate: pool.maxBorrowRate,
|
|
@@ -962,9 +1119,6 @@ var queryMarket = async (query) => {
|
|
|
962
1119
|
query.utils,
|
|
963
1120
|
parsedMarketPoolData
|
|
964
1121
|
);
|
|
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
1122
|
pools[poolCoinName] = {
|
|
969
1123
|
coinName: poolCoinName,
|
|
970
1124
|
symbol: query.utils.parseSymbol(poolCoinName),
|
|
@@ -983,6 +1137,12 @@ var queryMarket = async (query) => {
|
|
|
983
1137
|
};
|
|
984
1138
|
}
|
|
985
1139
|
for (const collateral of marketData.collaterals) {
|
|
1140
|
+
const coinType = normalizeStructTag2(collateral.type.name);
|
|
1141
|
+
const collateralCoinName = query.utils.parseCoinNameFromType(coinType);
|
|
1142
|
+
const coinPrice = (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName] ?? 0;
|
|
1143
|
+
if (!SUPPORT_COLLATERALS.includes(collateralCoinName)) {
|
|
1144
|
+
continue;
|
|
1145
|
+
}
|
|
986
1146
|
const parsedMarketCollateralData = parseOriginMarketCollateralData({
|
|
987
1147
|
type: collateral.type,
|
|
988
1148
|
collateralFactor: collateral.collateralFactor,
|
|
@@ -997,9 +1157,6 @@ var queryMarket = async (query) => {
|
|
|
997
1157
|
query.utils,
|
|
998
1158
|
parsedMarketCollateralData
|
|
999
1159
|
);
|
|
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
1160
|
collaterals[collateralCoinName] = {
|
|
1004
1161
|
coinName: collateralCoinName,
|
|
1005
1162
|
symbol: query.utils.parseSymbol(collateralCoinName),
|
|
@@ -1286,11 +1443,27 @@ var getObligations = async (query, ownerAddress) => {
|
|
|
1286
1443
|
if (keyObject.content && "fields" in keyObject.content) {
|
|
1287
1444
|
const fields = keyObject.content.fields;
|
|
1288
1445
|
const obligationId = String(fields.ownership.fields.of);
|
|
1289
|
-
|
|
1446
|
+
const locked = await getObligationLocked(query, obligationId);
|
|
1447
|
+
obligations.push({ id: obligationId, keyId, locked });
|
|
1290
1448
|
}
|
|
1291
1449
|
}
|
|
1292
1450
|
return obligations;
|
|
1293
1451
|
};
|
|
1452
|
+
var getObligationLocked = async (query, obligationId) => {
|
|
1453
|
+
const obligationObjectResponse = await query.suiKit.client().getObject({
|
|
1454
|
+
id: obligationId,
|
|
1455
|
+
options: {
|
|
1456
|
+
showContent: true
|
|
1457
|
+
}
|
|
1458
|
+
});
|
|
1459
|
+
let obligationLocked = false;
|
|
1460
|
+
if (obligationObjectResponse.data && obligationObjectResponse?.data?.content?.dataType === "moveObject" && "lock_key" in obligationObjectResponse.data.content.fields) {
|
|
1461
|
+
obligationLocked = Boolean(
|
|
1462
|
+
obligationObjectResponse.data.content.fields.lock_key
|
|
1463
|
+
);
|
|
1464
|
+
}
|
|
1465
|
+
return obligationLocked;
|
|
1466
|
+
};
|
|
1294
1467
|
var queryObligation = async (query, obligationId) => {
|
|
1295
1468
|
const packageId = query.address.get("core.packages.query.id");
|
|
1296
1469
|
const queryTarget = `${packageId}::obligation_query::obligation_data`;
|
|
@@ -1465,7 +1638,7 @@ var getMarketCoinAmount = async (query, marketCoinName, ownerAddress) => {
|
|
|
1465
1638
|
};
|
|
1466
1639
|
|
|
1467
1640
|
// src/queries/spoolQuery.ts
|
|
1468
|
-
import { normalizeStructTag } from "@mysten/sui.js/utils";
|
|
1641
|
+
import { normalizeStructTag as normalizeStructTag3 } from "@mysten/sui.js/utils";
|
|
1469
1642
|
var getSpools = async (query, stakeMarketCoinNames) => {
|
|
1470
1643
|
stakeMarketCoinNames = stakeMarketCoinNames || [...SUPPORT_SPOOLS];
|
|
1471
1644
|
const stakeCoinNames = stakeMarketCoinNames.map(
|
|
@@ -1486,31 +1659,31 @@ var getSpools = async (query, stakeMarketCoinNames) => {
|
|
|
1486
1659
|
}
|
|
1487
1660
|
return spools;
|
|
1488
1661
|
};
|
|
1489
|
-
var getSpool = async (query,
|
|
1490
|
-
const
|
|
1491
|
-
marketPool = marketPool || await query.getMarketPool(
|
|
1492
|
-
const poolId = query.address.get(`spool.pools.${
|
|
1662
|
+
var getSpool = async (query, marketCoinName, marketPool) => {
|
|
1663
|
+
const coinName = query.utils.parseCoinName(marketCoinName);
|
|
1664
|
+
marketPool = marketPool || await query.getMarketPool(coinName);
|
|
1665
|
+
const poolId = query.address.get(`spool.pools.${marketCoinName}.id`);
|
|
1493
1666
|
const rewardPoolId = query.address.get(
|
|
1494
|
-
`spool.pools.${
|
|
1667
|
+
`spool.pools.${marketCoinName}.rewardPoolId`
|
|
1495
1668
|
);
|
|
1496
1669
|
let spool = void 0;
|
|
1497
|
-
const
|
|
1670
|
+
const spoolObjectResponse = await query.suiKit.client().multiGetObjects({
|
|
1498
1671
|
ids: [poolId, rewardPoolId],
|
|
1499
1672
|
options: {
|
|
1500
1673
|
showContent: true
|
|
1501
1674
|
}
|
|
1502
1675
|
});
|
|
1503
|
-
if (marketPool &&
|
|
1504
|
-
const
|
|
1676
|
+
if (marketPool && spoolObjectResponse[0].data && spoolObjectResponse[1].data) {
|
|
1677
|
+
const rewardCoinName = query.utils.getSpoolRewardCoinName(marketCoinName);
|
|
1505
1678
|
const coinPrices = await query.utils.getCoinPrices([
|
|
1506
|
-
|
|
1507
|
-
|
|
1679
|
+
coinName,
|
|
1680
|
+
rewardCoinName
|
|
1508
1681
|
]);
|
|
1509
|
-
const
|
|
1510
|
-
const rewardPoolObject =
|
|
1511
|
-
if (
|
|
1512
|
-
const fields =
|
|
1513
|
-
const
|
|
1682
|
+
const spoolObject = spoolObjectResponse[0].data;
|
|
1683
|
+
const rewardPoolObject = spoolObjectResponse[1].data;
|
|
1684
|
+
if (spoolObject.content && "fields" in spoolObject.content) {
|
|
1685
|
+
const fields = spoolObject.content.fields;
|
|
1686
|
+
const parsedSpoolData = parseOriginSpoolData({
|
|
1514
1687
|
stakeType: fields.stake_type,
|
|
1515
1688
|
maxDistributedPoint: fields.max_distributed_point,
|
|
1516
1689
|
distributedPoint: fields.distributed_point,
|
|
@@ -1522,43 +1695,48 @@ var getSpool = async (query, stakeMarketCoinName, marketPool) => {
|
|
|
1522
1695
|
createdAt: fields.created_at,
|
|
1523
1696
|
lastUpdate: fields.last_update
|
|
1524
1697
|
});
|
|
1525
|
-
const
|
|
1526
|
-
const
|
|
1527
|
-
const
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1698
|
+
const marketCoinPrice = (coinPrices?.[coinName] ?? 0) * marketPool.conversionRate;
|
|
1699
|
+
const marketCoinDecimal = query.utils.getCoinDecimal(marketCoinName);
|
|
1700
|
+
const calculatedSpoolData = calculateSpoolData(
|
|
1701
|
+
parsedSpoolData,
|
|
1702
|
+
marketCoinPrice,
|
|
1703
|
+
marketCoinDecimal
|
|
1531
1704
|
);
|
|
1532
1705
|
if (rewardPoolObject.content && "fields" in rewardPoolObject.content) {
|
|
1533
1706
|
const fields2 = rewardPoolObject.content.fields;
|
|
1534
|
-
const
|
|
1707
|
+
const parsedSpoolRewardPoolData = parseOriginSpoolRewardPoolData({
|
|
1535
1708
|
claimed_rewards: fields2.claimed_rewards,
|
|
1536
1709
|
exchange_rate_numerator: fields2.exchange_rate_numerator,
|
|
1537
1710
|
exchange_rate_denominator: fields2.exchange_rate_denominator,
|
|
1538
1711
|
rewards: fields2.rewards,
|
|
1539
1712
|
spool_id: fields2.spool_id
|
|
1540
1713
|
});
|
|
1541
|
-
const rewardCoinPrice = coinPrices?.[
|
|
1542
|
-
const rewardCoinDecimal = query.utils.getCoinDecimal(
|
|
1543
|
-
const calculatedRewardPoolData =
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1714
|
+
const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
|
|
1715
|
+
const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
1716
|
+
const calculatedRewardPoolData = calculateSpoolRewardPoolData(
|
|
1717
|
+
parsedSpoolData,
|
|
1718
|
+
parsedSpoolRewardPoolData,
|
|
1719
|
+
calculatedSpoolData,
|
|
1547
1720
|
rewardCoinPrice,
|
|
1548
1721
|
rewardCoinDecimal
|
|
1549
1722
|
);
|
|
1550
1723
|
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
|
|
1724
|
+
marketCoinName,
|
|
1725
|
+
symbol: query.utils.parseSymbol(marketCoinName),
|
|
1726
|
+
coinType: query.utils.parseCoinType(coinName),
|
|
1727
|
+
marketCoinType: query.utils.parseMarketCoinType(coinName),
|
|
1728
|
+
rewardCoinType: isMarketCoin(rewardCoinName) ? query.utils.parseMarketCoinType(rewardCoinName) : query.utils.parseCoinType(rewardCoinName),
|
|
1729
|
+
coinDecimal: query.utils.getCoinDecimal(coinName),
|
|
1730
|
+
rewardCoinDecimal: query.utils.getCoinDecimal(rewardCoinName),
|
|
1731
|
+
coinPrice: coinPrices?.[coinName] ?? 0,
|
|
1732
|
+
marketCoinPrice,
|
|
1560
1733
|
rewardCoinPrice,
|
|
1561
|
-
|
|
1734
|
+
maxPoint: parsedSpoolData.maxPoint,
|
|
1735
|
+
distributedPoint: parsedSpoolData.distributedPoint,
|
|
1736
|
+
maxStake: parsedSpoolData.maxStake,
|
|
1737
|
+
...calculatedSpoolData,
|
|
1738
|
+
exchangeRateNumerator: parsedSpoolRewardPoolData.exchangeRateNumerator,
|
|
1739
|
+
exchangeRateDenominator: parsedSpoolRewardPoolData.exchangeRateDenominator,
|
|
1562
1740
|
...calculatedRewardPoolData
|
|
1563
1741
|
};
|
|
1564
1742
|
}
|
|
@@ -1616,34 +1794,34 @@ var getStakeAccounts = async (query, ownerAddress) => {
|
|
|
1616
1794
|
const index = Number(fields.index);
|
|
1617
1795
|
const points = Number(fields.points);
|
|
1618
1796
|
const totalPoints = Number(fields.total_points);
|
|
1619
|
-
if (
|
|
1797
|
+
if (normalizeStructTag3(type) === stakeMarketCoinTypes.ssui) {
|
|
1620
1798
|
stakeAccounts.ssui.push({
|
|
1621
1799
|
id,
|
|
1622
|
-
type,
|
|
1800
|
+
type: normalizeStructTag3(type),
|
|
1623
1801
|
stakePoolId,
|
|
1624
|
-
stakeType,
|
|
1802
|
+
stakeType: normalizeStructTag3(stakeType),
|
|
1625
1803
|
staked,
|
|
1626
1804
|
index,
|
|
1627
1805
|
points,
|
|
1628
1806
|
totalPoints
|
|
1629
1807
|
});
|
|
1630
|
-
} else if (
|
|
1808
|
+
} else if (normalizeStructTag3(type) === stakeMarketCoinTypes.susdc) {
|
|
1631
1809
|
stakeAccounts.susdc.push({
|
|
1632
1810
|
id,
|
|
1633
|
-
type,
|
|
1811
|
+
type: normalizeStructTag3(type),
|
|
1634
1812
|
stakePoolId,
|
|
1635
|
-
stakeType,
|
|
1813
|
+
stakeType: normalizeStructTag3(stakeType),
|
|
1636
1814
|
staked,
|
|
1637
1815
|
index,
|
|
1638
1816
|
points,
|
|
1639
1817
|
totalPoints
|
|
1640
1818
|
});
|
|
1641
|
-
} else if (
|
|
1819
|
+
} else if (normalizeStructTag3(type) === stakeMarketCoinTypes.susdt) {
|
|
1642
1820
|
stakeAccounts.susdt.push({
|
|
1643
1821
|
id,
|
|
1644
|
-
type,
|
|
1822
|
+
type: normalizeStructTag3(type),
|
|
1645
1823
|
stakePoolId,
|
|
1646
|
-
stakeType,
|
|
1824
|
+
stakeType: normalizeStructTag3(stakeType),
|
|
1647
1825
|
staked,
|
|
1648
1826
|
index,
|
|
1649
1827
|
points,
|
|
@@ -1682,13 +1860,13 @@ var getStakePool = async (query, marketCoinName) => {
|
|
|
1682
1860
|
const lastUpdate = Number(fields.last_update);
|
|
1683
1861
|
stakePool = {
|
|
1684
1862
|
id,
|
|
1685
|
-
type,
|
|
1863
|
+
type: normalizeStructTag3(type),
|
|
1686
1864
|
maxPoint,
|
|
1687
1865
|
distributedPoint,
|
|
1688
1866
|
pointPerPeriod,
|
|
1689
1867
|
period,
|
|
1690
1868
|
maxStake,
|
|
1691
|
-
stakeType,
|
|
1869
|
+
stakeType: normalizeStructTag3(stakeType),
|
|
1692
1870
|
totalStaked,
|
|
1693
1871
|
index,
|
|
1694
1872
|
createdAt,
|
|
@@ -1698,32 +1876,32 @@ var getStakePool = async (query, marketCoinName) => {
|
|
|
1698
1876
|
}
|
|
1699
1877
|
return stakePool;
|
|
1700
1878
|
};
|
|
1701
|
-
var
|
|
1879
|
+
var getStakeRewardPool = async (query, marketCoinName) => {
|
|
1702
1880
|
const poolId = query.address.get(
|
|
1703
1881
|
`spool.pools.${marketCoinName}.rewardPoolId`
|
|
1704
1882
|
);
|
|
1705
|
-
let
|
|
1706
|
-
const
|
|
1883
|
+
let stakeRewardPool = void 0;
|
|
1884
|
+
const stakeRewardPoolObjectResponse = await query.suiKit.client().getObject({
|
|
1707
1885
|
id: poolId,
|
|
1708
1886
|
options: {
|
|
1709
1887
|
showContent: true,
|
|
1710
1888
|
showType: true
|
|
1711
1889
|
}
|
|
1712
1890
|
});
|
|
1713
|
-
if (
|
|
1714
|
-
const
|
|
1715
|
-
const id =
|
|
1716
|
-
const type =
|
|
1717
|
-
if (
|
|
1718
|
-
const fields =
|
|
1891
|
+
if (stakeRewardPoolObjectResponse.data) {
|
|
1892
|
+
const stakeRewardPoolObject = stakeRewardPoolObjectResponse.data;
|
|
1893
|
+
const id = stakeRewardPoolObject.objectId;
|
|
1894
|
+
const type = stakeRewardPoolObject.type;
|
|
1895
|
+
if (stakeRewardPoolObject.content && "fields" in stakeRewardPoolObject.content) {
|
|
1896
|
+
const fields = stakeRewardPoolObject.content.fields;
|
|
1719
1897
|
const stakePoolId = String(fields.spool_id);
|
|
1720
1898
|
const ratioNumerator = Number(fields.exchange_rate_numerator);
|
|
1721
1899
|
const ratioDenominator = Number(fields.exchange_rate_denominator);
|
|
1722
1900
|
const rewards = Number(fields.rewards);
|
|
1723
1901
|
const claimedRewards = Number(fields.claimed_rewards);
|
|
1724
|
-
|
|
1902
|
+
stakeRewardPool = {
|
|
1725
1903
|
id,
|
|
1726
|
-
type,
|
|
1904
|
+
type: normalizeStructTag3(type),
|
|
1727
1905
|
stakePoolId,
|
|
1728
1906
|
ratioNumerator,
|
|
1729
1907
|
ratioDenominator,
|
|
@@ -1732,7 +1910,107 @@ var getRewardPool = async (query, marketCoinName) => {
|
|
|
1732
1910
|
};
|
|
1733
1911
|
}
|
|
1734
1912
|
}
|
|
1735
|
-
return
|
|
1913
|
+
return stakeRewardPool;
|
|
1914
|
+
};
|
|
1915
|
+
|
|
1916
|
+
// src/queries/borrowIncentiveQuery.ts
|
|
1917
|
+
import { normalizeStructTag as normalizeStructTag4 } from "@mysten/sui.js/utils";
|
|
1918
|
+
import { SuiTxBlock as SuiKitTxBlock2 } from "@scallop-io/sui-kit";
|
|
1919
|
+
var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames) => {
|
|
1920
|
+
borrowIncentiveCoinNames = borrowIncentiveCoinNames || [
|
|
1921
|
+
...SUPPORT_BORROW_INCENTIVE_POOLS
|
|
1922
|
+
];
|
|
1923
|
+
const queryPkgId = query.address.get("borrowIncentive.query");
|
|
1924
|
+
const incentivePoolsId = query.address.get("borrowIncentive.incentivePools");
|
|
1925
|
+
const txBlock = new SuiKitTxBlock2();
|
|
1926
|
+
const queryTarget = `${queryPkgId}::incentive_pools_query::incentive_pools_data`;
|
|
1927
|
+
txBlock.moveCall(queryTarget, [incentivePoolsId], ["0x2::sui::SUI"]);
|
|
1928
|
+
const queryResult = await query.suiKit.inspectTxn(txBlock);
|
|
1929
|
+
const borrowIncentivePoolsQueryData = queryResult.events[0].parsedJson;
|
|
1930
|
+
const parsedBorrowIncentiveRewardPoolData = parseOriginBorrowIncentiveRewardPoolData(
|
|
1931
|
+
borrowIncentivePoolsQueryData.reward_pool
|
|
1932
|
+
);
|
|
1933
|
+
const rewardCoinType = parsedBorrowIncentiveRewardPoolData.rewardType;
|
|
1934
|
+
const borrowIncentivePools = {};
|
|
1935
|
+
for (const pool of borrowIncentivePoolsQueryData.incentive_pools) {
|
|
1936
|
+
const coinType = normalizeStructTag4(pool.pool_type.name);
|
|
1937
|
+
const coinName = query.utils.parseCoinNameFromType(coinType);
|
|
1938
|
+
const rewardCoinName = query.utils.parseCoinNameFromType(rewardCoinType);
|
|
1939
|
+
if (!borrowIncentiveCoinNames.includes(coinName)) {
|
|
1940
|
+
continue;
|
|
1941
|
+
}
|
|
1942
|
+
const coinPrices = await query.utils.getCoinPrices([
|
|
1943
|
+
coinName,
|
|
1944
|
+
rewardCoinName
|
|
1945
|
+
]);
|
|
1946
|
+
const parsedBorrowIncentivePoolData = parseOriginBorrowIncentivePoolData(pool);
|
|
1947
|
+
const coinPrice = coinPrices?.[coinName] ?? 0;
|
|
1948
|
+
const coinDecimal = query.utils.getCoinDecimal(coinName);
|
|
1949
|
+
const calculatedBorrowIncentivePoolData = calculateBorrowIncentivePoolData(
|
|
1950
|
+
parsedBorrowIncentivePoolData,
|
|
1951
|
+
coinPrice,
|
|
1952
|
+
coinDecimal
|
|
1953
|
+
);
|
|
1954
|
+
const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
|
|
1955
|
+
const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
1956
|
+
const calculatedBorrowIncentiveRewardPoolData = calculateBorrowIncentiveRewardPoolData(
|
|
1957
|
+
parsedBorrowIncentivePoolData,
|
|
1958
|
+
parsedBorrowIncentiveRewardPoolData,
|
|
1959
|
+
calculatedBorrowIncentivePoolData,
|
|
1960
|
+
rewardCoinPrice,
|
|
1961
|
+
rewardCoinDecimal
|
|
1962
|
+
);
|
|
1963
|
+
borrowIncentivePools[coinName] = {
|
|
1964
|
+
coinName,
|
|
1965
|
+
symbol: query.utils.parseSymbol(coinName),
|
|
1966
|
+
coinType,
|
|
1967
|
+
rewardCoinType,
|
|
1968
|
+
coinDecimal,
|
|
1969
|
+
rewardCoinDecimal,
|
|
1970
|
+
coinPrice,
|
|
1971
|
+
rewardCoinPrice,
|
|
1972
|
+
maxPoint: parsedBorrowIncentivePoolData.maxPoint,
|
|
1973
|
+
distributedPoint: parsedBorrowIncentivePoolData.distributedPoint,
|
|
1974
|
+
maxStake: parsedBorrowIncentivePoolData.maxStake,
|
|
1975
|
+
...calculatedBorrowIncentivePoolData,
|
|
1976
|
+
exchangeRateNumerator: parsedBorrowIncentiveRewardPoolData.exchangeRateNumerator,
|
|
1977
|
+
exchangeRateDenominator: parsedBorrowIncentiveRewardPoolData.exchangeRateDenominator,
|
|
1978
|
+
...calculatedBorrowIncentiveRewardPoolData
|
|
1979
|
+
};
|
|
1980
|
+
}
|
|
1981
|
+
return borrowIncentivePools;
|
|
1982
|
+
};
|
|
1983
|
+
var queryBorrowIncentiveAccounts = async (query, obligationId, borrowIncentiveCoinNames) => {
|
|
1984
|
+
borrowIncentiveCoinNames = borrowIncentiveCoinNames || [
|
|
1985
|
+
...SUPPORT_BORROW_INCENTIVE_POOLS
|
|
1986
|
+
];
|
|
1987
|
+
const queryPkgId = query.address.get("borrowIncentive.query");
|
|
1988
|
+
const incentiveAccountsId = query.address.get(
|
|
1989
|
+
"borrowIncentive.incentiveAccounts"
|
|
1990
|
+
);
|
|
1991
|
+
const queryTarget = `${queryPkgId}::incentive_account_query::incentive_account_data`;
|
|
1992
|
+
const txBlock = new SuiKitTxBlock2();
|
|
1993
|
+
txBlock.moveCall(queryTarget, [incentiveAccountsId, obligationId]);
|
|
1994
|
+
const queryResult = await query.suiKit.inspectTxn(txBlock);
|
|
1995
|
+
const borrowIncentiveAccountsQueryData = queryResult.events[0].parsedJson;
|
|
1996
|
+
const borrowIncentiveAccounts = Object.values(
|
|
1997
|
+
borrowIncentiveAccountsQueryData.incentive_states
|
|
1998
|
+
).reduce((accounts, accountData) => {
|
|
1999
|
+
const parsedBorrowIncentiveAccount = parseOriginBorrowIncentiveAccountData(accountData);
|
|
2000
|
+
const poolType = parsedBorrowIncentiveAccount.poolType;
|
|
2001
|
+
const coinName = query.utils.parseCoinNameFromType(poolType);
|
|
2002
|
+
if (borrowIncentiveCoinNames && borrowIncentiveCoinNames.includes(coinName)) {
|
|
2003
|
+
accounts[coinName] = {
|
|
2004
|
+
poolType,
|
|
2005
|
+
amount: parsedBorrowIncentiveAccount.amount,
|
|
2006
|
+
points: parsedBorrowIncentiveAccount.points,
|
|
2007
|
+
totalPoints: parsedBorrowIncentiveAccount.totalPoints,
|
|
2008
|
+
index: parsedBorrowIncentiveAccount.index
|
|
2009
|
+
};
|
|
2010
|
+
}
|
|
2011
|
+
return accounts;
|
|
2012
|
+
}, {});
|
|
2013
|
+
return borrowIncentiveAccounts;
|
|
1736
2014
|
};
|
|
1737
2015
|
|
|
1738
2016
|
// src/queries/priceQuery.ts
|
|
@@ -1853,15 +2131,19 @@ var getLending = async (query, poolCoinName, ownerAddress, marketPool, spool, st
|
|
|
1853
2131
|
availableUnstakeAmount = availableUnstakeAmount.plus(
|
|
1854
2132
|
accountStakedMarketCoinAmount
|
|
1855
2133
|
);
|
|
1856
|
-
availableUnstakeCoin = availableUnstakeAmount.shiftedBy(
|
|
2134
|
+
availableUnstakeCoin = availableUnstakeAmount.shiftedBy(
|
|
2135
|
+
-1 * spool.coinDecimal
|
|
2136
|
+
);
|
|
1857
2137
|
const baseIndexRate = 1e9;
|
|
1858
2138
|
const increasedPointRate = spool?.currentPointIndex ? BigNumber3(spool.currentPointIndex - stakeAccount.index).dividedBy(
|
|
1859
2139
|
baseIndexRate
|
|
1860
2140
|
) : 1;
|
|
1861
2141
|
availableClaimAmount = availableClaimAmount.plus(
|
|
1862
|
-
|
|
2142
|
+
accountStakedMarketCoinAmount.multipliedBy(increasedPointRate).plus(stakeAccount.points).multipliedBy(spool.exchangeRateNumerator).dividedBy(spool.exchangeRateDenominator)
|
|
2143
|
+
);
|
|
2144
|
+
availableClaimCoin = availableClaimAmount.shiftedBy(
|
|
2145
|
+
-1 * spool.rewardCoinDecimal
|
|
1863
2146
|
);
|
|
1864
|
-
availableClaimCoin = availableClaimAmount.shiftedBy(-1 * coinDecimal);
|
|
1865
2147
|
}
|
|
1866
2148
|
}
|
|
1867
2149
|
const suppliedAmount = BigNumber3(marketCoinAmount).multipliedBy(
|
|
@@ -1946,10 +2228,13 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
|
|
|
1946
2228
|
])
|
|
1947
2229
|
];
|
|
1948
2230
|
const obligationQuery = await query.queryObligation(obligationId);
|
|
2231
|
+
const borrowIncentivePools = await query.getBorrowIncentivePools();
|
|
2232
|
+
const borrowIncentiveAccounts = await query.getBorrowIncentiveAccounts(obligationId);
|
|
1949
2233
|
coinPrices = coinPrices || await query.utils.getCoinPrices(assetCoinNames);
|
|
1950
2234
|
coinAmounts = coinAmounts || await query.getCoinAmounts(assetCoinNames, ownerAddress);
|
|
1951
2235
|
const collaterals = {};
|
|
1952
2236
|
const debts = {};
|
|
2237
|
+
const borrowIncentives = {};
|
|
1953
2238
|
let totalDepositedPools = 0;
|
|
1954
2239
|
let totalDepositedValue = BigNumber3(0);
|
|
1955
2240
|
let totalBorrowCapacityValue = BigNumber3(0);
|
|
@@ -2051,6 +2336,41 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
|
|
|
2051
2336
|
};
|
|
2052
2337
|
}
|
|
2053
2338
|
}
|
|
2339
|
+
for (const [poolCoinName, borrowIncentiveAccount] of Object.entries(
|
|
2340
|
+
borrowIncentiveAccounts
|
|
2341
|
+
)) {
|
|
2342
|
+
const coinName = poolCoinName;
|
|
2343
|
+
const borrowIncentivePool = borrowIncentivePools[coinName];
|
|
2344
|
+
let availableClaimAmount = BigNumber3(0);
|
|
2345
|
+
let availableClaimCoin = BigNumber3(0);
|
|
2346
|
+
if (borrowIncentivePool) {
|
|
2347
|
+
const accountBorrowedAmount = BigNumber3(borrowIncentiveAccount.amount);
|
|
2348
|
+
const baseIndexRate = 1e9;
|
|
2349
|
+
const increasedPointRate = borrowIncentivePool.currentPointIndex ? BigNumber3(
|
|
2350
|
+
borrowIncentivePool.currentPointIndex - borrowIncentiveAccount.index
|
|
2351
|
+
).dividedBy(baseIndexRate) : 1;
|
|
2352
|
+
availableClaimAmount = availableClaimAmount.plus(
|
|
2353
|
+
accountBorrowedAmount.multipliedBy(increasedPointRate).plus(borrowIncentiveAccount.points).multipliedBy(borrowIncentivePool.exchangeRateNumerator).dividedBy(borrowIncentivePool.exchangeRateDenominator)
|
|
2354
|
+
);
|
|
2355
|
+
availableClaimCoin = availableClaimAmount.shiftedBy(
|
|
2356
|
+
-1 * borrowIncentivePool.rewardCoinDecimal
|
|
2357
|
+
);
|
|
2358
|
+
if (availableClaimAmount.isGreaterThan(0)) {
|
|
2359
|
+
borrowIncentives[coinName] = {
|
|
2360
|
+
coinName: borrowIncentivePool.coinName,
|
|
2361
|
+
coinType: borrowIncentivePool.coinType,
|
|
2362
|
+
rewardCoinType: borrowIncentivePool.rewardCoinType,
|
|
2363
|
+
symbol: borrowIncentivePool.symbol,
|
|
2364
|
+
coinDecimal: borrowIncentivePool.coinDecimal,
|
|
2365
|
+
rewardCoinDecimal: borrowIncentivePool.rewardCoinDecimal,
|
|
2366
|
+
coinPrice: borrowIncentivePool.coinPrice,
|
|
2367
|
+
rewardCoinPrice: borrowIncentivePool.rewardCoinPrice,
|
|
2368
|
+
availableClaimAmount: availableClaimAmount.toNumber(),
|
|
2369
|
+
availableClaimCoin: availableClaimCoin.toNumber()
|
|
2370
|
+
};
|
|
2371
|
+
}
|
|
2372
|
+
}
|
|
2373
|
+
}
|
|
2054
2374
|
let riskLevel = totalRequiredCollateralValue.isZero() && totalBorrowedValueWithWeight.isZero() ? BigNumber3(0) : totalBorrowedValueWithWeight.dividedBy(totalRequiredCollateralValue);
|
|
2055
2375
|
riskLevel = riskLevel.isFinite() ? riskLevel.isLessThan(1) ? riskLevel : BigNumber3(1) : BigNumber3(1);
|
|
2056
2376
|
const accountBalanceValue = totalDepositedValue.minus(totalBorrowedValue).isGreaterThan(0) ? totalDepositedValue.minus(totalBorrowedValue) : BigNumber3(0);
|
|
@@ -2079,7 +2399,8 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
|
|
|
2079
2399
|
totalDepositedPools,
|
|
2080
2400
|
totalBorrowedPools,
|
|
2081
2401
|
collaterals,
|
|
2082
|
-
debts
|
|
2402
|
+
debts,
|
|
2403
|
+
borrowIncentives
|
|
2083
2404
|
};
|
|
2084
2405
|
for (const [collateralCoinName, obligationCollateral] of Object.entries(
|
|
2085
2406
|
obligationAccount.collaterals
|
|
@@ -2095,10 +2416,10 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
|
|
|
2095
2416
|
obligationCollateral.availableWithdrawCoin = availableWithdrawAmount.shiftedBy(-1 * obligationCollateral.coinDecimal).toNumber();
|
|
2096
2417
|
}
|
|
2097
2418
|
}
|
|
2098
|
-
for (const [
|
|
2419
|
+
for (const [poolCoinName, obligationDebt] of Object.entries(
|
|
2099
2420
|
obligationAccount.debts
|
|
2100
2421
|
)) {
|
|
2101
|
-
const marketPool = market.pools[
|
|
2422
|
+
const marketPool = market.pools[poolCoinName];
|
|
2102
2423
|
if (marketPool) {
|
|
2103
2424
|
const availableRepayAmount = BigNumber3(
|
|
2104
2425
|
obligationDebt.availableRepayAmount
|
|
@@ -2364,38 +2685,60 @@ var ScallopQuery = class {
|
|
|
2364
2685
|
return await getStakePool(this, stakeMarketCoinName);
|
|
2365
2686
|
}
|
|
2366
2687
|
/**
|
|
2367
|
-
* Get reward pools data.
|
|
2688
|
+
* Get stake reward pools data.
|
|
2368
2689
|
*
|
|
2369
2690
|
* @description
|
|
2370
2691
|
* For backward compatible, it is recommended to use `getSpools` method
|
|
2371
2692
|
* to get all spools data.
|
|
2372
2693
|
*
|
|
2373
2694
|
* @param stakeMarketCoinNames - Specific an array of stake market coin name.
|
|
2374
|
-
* @return
|
|
2695
|
+
* @return Stake reward pools data.
|
|
2375
2696
|
*/
|
|
2376
|
-
async
|
|
2697
|
+
async getStakeRewardPools(stakeMarketCoinNames) {
|
|
2377
2698
|
stakeMarketCoinNames = stakeMarketCoinNames ?? [...SUPPORT_SPOOLS];
|
|
2378
|
-
const
|
|
2699
|
+
const stakeRewardPools = {};
|
|
2379
2700
|
for (const stakeMarketCoinName of stakeMarketCoinNames) {
|
|
2380
|
-
const
|
|
2381
|
-
|
|
2382
|
-
|
|
2701
|
+
const stakeRewardPool = await getStakeRewardPool(
|
|
2702
|
+
this,
|
|
2703
|
+
stakeMarketCoinName
|
|
2704
|
+
);
|
|
2705
|
+
if (stakeRewardPool) {
|
|
2706
|
+
stakeRewardPools[stakeMarketCoinName] = stakeRewardPool;
|
|
2383
2707
|
}
|
|
2384
2708
|
}
|
|
2385
|
-
return
|
|
2709
|
+
return stakeRewardPools;
|
|
2386
2710
|
}
|
|
2387
2711
|
/**
|
|
2388
|
-
* Get reward pool data.
|
|
2712
|
+
* Get stake reward pool data.
|
|
2389
2713
|
*
|
|
2390
2714
|
* @description
|
|
2391
2715
|
* For backward compatible, it is recommended to use `getSpool` method
|
|
2392
2716
|
* to get spool data.
|
|
2393
2717
|
*
|
|
2394
2718
|
* @param marketCoinName - Specific support stake market coin name.
|
|
2395
|
-
* @return
|
|
2719
|
+
* @return Stake reward pool data.
|
|
2396
2720
|
*/
|
|
2397
|
-
async
|
|
2398
|
-
return await
|
|
2721
|
+
async getStakeRewardPool(stakeMarketCoinName) {
|
|
2722
|
+
return await getStakeRewardPool(this, stakeMarketCoinName);
|
|
2723
|
+
}
|
|
2724
|
+
/**
|
|
2725
|
+
* Get borrow incentive pools data.
|
|
2726
|
+
*
|
|
2727
|
+
* @param coinNames - Specific an array of support borrow incentive coin name.
|
|
2728
|
+
* @return Borrow incentive pools data.
|
|
2729
|
+
*/
|
|
2730
|
+
async getBorrowIncentivePools(coinNames) {
|
|
2731
|
+
return await queryBorrowIncentivePools(this, coinNames);
|
|
2732
|
+
}
|
|
2733
|
+
/**
|
|
2734
|
+
* Get borrow incentive accounts data.
|
|
2735
|
+
*
|
|
2736
|
+
* @param coinNames - Specific support borrow incentive coin name.
|
|
2737
|
+
* @param ownerAddress - The owner address.
|
|
2738
|
+
* @return Borrow incentive accounts data.
|
|
2739
|
+
*/
|
|
2740
|
+
async getBorrowIncentiveAccounts(obligationId, coinNames) {
|
|
2741
|
+
return await queryBorrowIncentiveAccounts(this, obligationId, coinNames);
|
|
2399
2742
|
}
|
|
2400
2743
|
/**
|
|
2401
2744
|
* Get user lending and spool infomation for specific pools.
|
|
@@ -2459,13 +2802,22 @@ var ScallopUtils = class {
|
|
|
2459
2802
|
constructor(params, instance) {
|
|
2460
2803
|
this._priceMap = /* @__PURE__ */ new Map();
|
|
2461
2804
|
/**
|
|
2462
|
-
* Get reward type of
|
|
2805
|
+
* Get reward type of spool.
|
|
2463
2806
|
*
|
|
2464
2807
|
* @param stakeMarketCoinName - Support stake market coin.
|
|
2465
|
-
* @return
|
|
2808
|
+
* @return Spool reward coin name.
|
|
2809
|
+
*/
|
|
2810
|
+
this.getSpoolRewardCoinName = (stakeMarketCoinName) => {
|
|
2811
|
+
return spoolRewardCoins[stakeMarketCoinName];
|
|
2812
|
+
};
|
|
2813
|
+
/**
|
|
2814
|
+
* Get reward type of borrow incentive pool.
|
|
2815
|
+
*
|
|
2816
|
+
* @param borrowIncentiveCoinName - Support borrow incentive coin.
|
|
2817
|
+
* @return Borrow incentive reward coin name.
|
|
2466
2818
|
*/
|
|
2467
|
-
this.
|
|
2468
|
-
return
|
|
2819
|
+
this.getBorrowIncentiveRewardCoinName = (borrowIncentiveCoinName) => {
|
|
2820
|
+
return borrowIncentiveRewardCoins[borrowIncentiveCoinName];
|
|
2469
2821
|
};
|
|
2470
2822
|
this.params = params;
|
|
2471
2823
|
this._suiKit = instance?.suiKit ?? new SuiKit2(params);
|
|
@@ -2522,7 +2874,7 @@ var ScallopUtils = class {
|
|
|
2522
2874
|
throw Error(`Coin ${coinName} is not supported`);
|
|
2523
2875
|
}
|
|
2524
2876
|
if (coinName === "sui")
|
|
2525
|
-
return
|
|
2877
|
+
return normalizeStructTag5(`${coinPackageId}::sui::SUI`);
|
|
2526
2878
|
const wormHolePckageIds = [
|
|
2527
2879
|
this._address.get("core.coins.usdc.id") ?? wormholeCoinIds.usdc,
|
|
2528
2880
|
this._address.get("core.coins.usdt.id") ?? wormholeCoinIds.usdt,
|
|
@@ -2554,7 +2906,7 @@ var ScallopUtils = class {
|
|
|
2554
2906
|
return `${PROTOCOL_OBJECT_ID}::reserve::MarketCoin<${coinType}>`;
|
|
2555
2907
|
}
|
|
2556
2908
|
parseCoinNameFromType(coinType) {
|
|
2557
|
-
coinType =
|
|
2909
|
+
coinType = normalizeStructTag5(coinType);
|
|
2558
2910
|
const coinTypeRegex = new RegExp(`((0x[^:]+::[^:]+::[^<>]+))(?![^<>]*<)`);
|
|
2559
2911
|
const coinTypeMatch = coinType.match(coinTypeRegex);
|
|
2560
2912
|
const isMarketCoinType = coinType.includes("reserve::MarketCoin");
|
|
@@ -2744,7 +3096,7 @@ import { SuiKit as SuiKit3 } from "@scallop-io/sui-kit";
|
|
|
2744
3096
|
// src/builders/coreBuilder.ts
|
|
2745
3097
|
import { TransactionBlock } from "@mysten/sui.js/transactions";
|
|
2746
3098
|
import { SUI_CLOCK_OBJECT_ID as SUI_CLOCK_OBJECT_ID2 } from "@mysten/sui.js/utils";
|
|
2747
|
-
import { SuiTxBlock as
|
|
3099
|
+
import { SuiTxBlock as SuiKitTxBlock3 } from "@scallop-io/sui-kit";
|
|
2748
3100
|
|
|
2749
3101
|
// src/builders/oracle.ts
|
|
2750
3102
|
import { SUI_CLOCK_OBJECT_ID } from "@mysten/sui.js/utils";
|
|
@@ -2882,13 +3234,6 @@ var updatePythPrice = (txBlock, packageId, request, stateId, feedObjectId, regis
|
|
|
2882
3234
|
};
|
|
2883
3235
|
|
|
2884
3236
|
// 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
3237
|
var requireObligationInfo = async (...params) => {
|
|
2893
3238
|
const [builder, txBlock, obligationId, obligationKey] = params;
|
|
2894
3239
|
if (params.length === 3 && obligationId)
|
|
@@ -3178,7 +3523,7 @@ var generateCoreQuickMethod = ({
|
|
|
3178
3523
|
};
|
|
3179
3524
|
};
|
|
3180
3525
|
var newCoreTxBlock = (builder, initTxBlock) => {
|
|
3181
|
-
const txBlock = initTxBlock instanceof TransactionBlock ? new
|
|
3526
|
+
const txBlock = initTxBlock instanceof TransactionBlock ? new SuiKitTxBlock3(initTxBlock) : initTxBlock ? initTxBlock : new SuiKitTxBlock3();
|
|
3182
3527
|
const normalMethod = generateCoreNormalMethod({
|
|
3183
3528
|
builder,
|
|
3184
3529
|
txBlock
|
|
@@ -3208,19 +3553,12 @@ var newCoreTxBlock = (builder, initTxBlock) => {
|
|
|
3208
3553
|
// src/builders/spoolBuilder.ts
|
|
3209
3554
|
import { TransactionBlock as TransactionBlock2 } from "@mysten/sui.js/transactions";
|
|
3210
3555
|
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
|
-
};
|
|
3556
|
+
import { SuiTxBlock as SuiKitTxBlock4 } from "@scallop-io/sui-kit";
|
|
3219
3557
|
var requireStakeAccountIds = async (...params) => {
|
|
3220
3558
|
const [builder, txBlock, stakeMarketCoinName, stakeAccountId] = params;
|
|
3221
3559
|
if (params.length === 4 && stakeAccountId)
|
|
3222
3560
|
return [stakeAccountId];
|
|
3223
|
-
const sender =
|
|
3561
|
+
const sender = requireSender(txBlock);
|
|
3224
3562
|
const stakeAccounts = await getStakeAccounts(builder.query, sender);
|
|
3225
3563
|
if (stakeAccounts[stakeMarketCoinName].length === 0) {
|
|
3226
3564
|
throw new Error(`No stake account id found for sender ${sender}`);
|
|
@@ -3229,7 +3567,7 @@ var requireStakeAccountIds = async (...params) => {
|
|
|
3229
3567
|
};
|
|
3230
3568
|
var requireStakeAccounts = async (...params) => {
|
|
3231
3569
|
const [builder, txBlock, stakeMarketCoinName, stakeAccountId] = params;
|
|
3232
|
-
const sender =
|
|
3570
|
+
const sender = requireSender(txBlock);
|
|
3233
3571
|
const stakeAccounts = await getStakeAccounts(builder.query, sender);
|
|
3234
3572
|
if (stakeAccounts[stakeMarketCoinName].length === 0) {
|
|
3235
3573
|
throw new Error(`No stake account found for sender ${sender}`);
|
|
@@ -3288,7 +3626,7 @@ var generateSpoolNormalMethod = ({
|
|
|
3288
3626
|
`spool.pools.${stakeMarketCoinName}.rewardPoolId`
|
|
3289
3627
|
);
|
|
3290
3628
|
const marketCoinType = builder.utils.parseMarketCoinType(stakeMarketCoinName);
|
|
3291
|
-
const rewardCoinName =
|
|
3629
|
+
const rewardCoinName = spoolRewardCoins[stakeMarketCoinName];
|
|
3292
3630
|
const rewardCoinType = builder.utils.parseCoinType(rewardCoinName);
|
|
3293
3631
|
return txBlock.moveCall(
|
|
3294
3632
|
`${spoolIds.spoolPkg}::user::redeem_rewards`,
|
|
@@ -3304,7 +3642,7 @@ var generateSpoolQuickMethod = ({
|
|
|
3304
3642
|
}) => {
|
|
3305
3643
|
return {
|
|
3306
3644
|
stakeQuick: async (amountOrMarketCoin, stakeMarketCoinName, stakeAccountId) => {
|
|
3307
|
-
const sender =
|
|
3645
|
+
const sender = requireSender(txBlock);
|
|
3308
3646
|
const stakeAccountIds = await requireStakeAccountIds(
|
|
3309
3647
|
builder,
|
|
3310
3648
|
txBlock,
|
|
@@ -3363,17 +3701,17 @@ var generateSpoolQuickMethod = ({
|
|
|
3363
3701
|
stakeMarketCoinName,
|
|
3364
3702
|
stakeAccountId
|
|
3365
3703
|
);
|
|
3366
|
-
const
|
|
3704
|
+
const rewardCoins = [];
|
|
3367
3705
|
for (const accountId of stakeAccountIds) {
|
|
3368
3706
|
const rewardCoin = txBlock.claim(accountId, stakeMarketCoinName);
|
|
3369
|
-
|
|
3707
|
+
rewardCoins.push(rewardCoin);
|
|
3370
3708
|
}
|
|
3371
|
-
return
|
|
3709
|
+
return rewardCoins;
|
|
3372
3710
|
}
|
|
3373
3711
|
};
|
|
3374
3712
|
};
|
|
3375
3713
|
var newSpoolTxBlock = (builder, initTxBlock) => {
|
|
3376
|
-
const txBlock = initTxBlock instanceof TransactionBlock2 ? new
|
|
3714
|
+
const txBlock = initTxBlock instanceof TransactionBlock2 ? new SuiKitTxBlock4(initTxBlock) : initTxBlock ? initTxBlock : new SuiKitTxBlock4();
|
|
3377
3715
|
const normalMethod = generateSpoolNormalMethod({
|
|
3378
3716
|
builder,
|
|
3379
3717
|
txBlock
|
|
@@ -3400,13 +3738,183 @@ var newSpoolTxBlock = (builder, initTxBlock) => {
|
|
|
3400
3738
|
});
|
|
3401
3739
|
};
|
|
3402
3740
|
|
|
3741
|
+
// src/builders/borrowIncentiveBuilder.ts
|
|
3742
|
+
import { TransactionBlock as TransactionBlock3 } from "@mysten/sui.js/transactions";
|
|
3743
|
+
import { SUI_CLOCK_OBJECT_ID as SUI_CLOCK_OBJECT_ID4 } from "@mysten/sui.js/utils";
|
|
3744
|
+
import { SuiTxBlock as SuiKitTxBlock5 } from "@scallop-io/sui-kit";
|
|
3745
|
+
var requireObligationInfo2 = async (...params) => {
|
|
3746
|
+
const [builder, txBlock, obligationId, obligationKey] = params;
|
|
3747
|
+
if (params.length === 4 && obligationId && obligationKey && typeof obligationId === "string") {
|
|
3748
|
+
const obligationLocked = await getObligationLocked(
|
|
3749
|
+
builder.query,
|
|
3750
|
+
obligationId
|
|
3751
|
+
);
|
|
3752
|
+
return { obligationId, obligationKey, obligationLocked };
|
|
3753
|
+
}
|
|
3754
|
+
const sender = requireSender(txBlock);
|
|
3755
|
+
const obligations = await getObligations(builder.query, sender);
|
|
3756
|
+
if (obligations.length === 0) {
|
|
3757
|
+
throw new Error(`No obligation found for sender ${sender}`);
|
|
3758
|
+
}
|
|
3759
|
+
return {
|
|
3760
|
+
obligationId: obligations[0].id,
|
|
3761
|
+
obligationKey: obligations[0].keyId,
|
|
3762
|
+
obligationLocked: obligations[0].locked
|
|
3763
|
+
};
|
|
3764
|
+
};
|
|
3765
|
+
var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
|
|
3766
|
+
const borrowIncentiveIds = {
|
|
3767
|
+
borrowIncentivePkg: builder.address.get("borrowIncentive.id"),
|
|
3768
|
+
query: builder.address.get("borrowIncentive.query"),
|
|
3769
|
+
incentivePools: builder.address.get("borrowIncentive.incentivePools"),
|
|
3770
|
+
incentiveAccounts: builder.address.get(
|
|
3771
|
+
"borrowIncentive.incentiveAccounts"
|
|
3772
|
+
),
|
|
3773
|
+
obligationAccessStore: builder.address.get("core.obligationAccessStore")
|
|
3774
|
+
};
|
|
3775
|
+
return {
|
|
3776
|
+
stakeObligation: (obligationId, obligaionKey, coinName) => {
|
|
3777
|
+
const rewardCoinName = borrowIncentiveRewardCoins[coinName];
|
|
3778
|
+
const rewardType = builder.utils.parseCoinType(rewardCoinName);
|
|
3779
|
+
txBlock.moveCall(
|
|
3780
|
+
`${borrowIncentiveIds.borrowIncentivePkg}::user::stake`,
|
|
3781
|
+
[
|
|
3782
|
+
borrowIncentiveIds.incentivePools,
|
|
3783
|
+
borrowIncentiveIds.incentiveAccounts,
|
|
3784
|
+
obligaionKey,
|
|
3785
|
+
obligationId,
|
|
3786
|
+
borrowIncentiveIds.obligationAccessStore,
|
|
3787
|
+
SUI_CLOCK_OBJECT_ID4
|
|
3788
|
+
],
|
|
3789
|
+
[rewardType]
|
|
3790
|
+
);
|
|
3791
|
+
},
|
|
3792
|
+
unstakeObligation: (obligationId, obligaionKey, coinName) => {
|
|
3793
|
+
const rewardCoinName = borrowIncentiveRewardCoins[coinName];
|
|
3794
|
+
const rewardType = builder.utils.parseCoinType(rewardCoinName);
|
|
3795
|
+
txBlock.moveCall(
|
|
3796
|
+
`${borrowIncentiveIds.borrowIncentivePkg}::user::unstake`,
|
|
3797
|
+
[
|
|
3798
|
+
borrowIncentiveIds.incentivePools,
|
|
3799
|
+
borrowIncentiveIds.incentiveAccounts,
|
|
3800
|
+
obligaionKey,
|
|
3801
|
+
obligationId,
|
|
3802
|
+
SUI_CLOCK_OBJECT_ID4
|
|
3803
|
+
],
|
|
3804
|
+
[rewardType]
|
|
3805
|
+
);
|
|
3806
|
+
},
|
|
3807
|
+
claimBorrowIncentive: (obligationId, obligaionKey, coinName) => {
|
|
3808
|
+
const rewardCoinName = borrowIncentiveRewardCoins[coinName];
|
|
3809
|
+
const rewardType = builder.utils.parseCoinType(rewardCoinName);
|
|
3810
|
+
return txBlock.moveCall(
|
|
3811
|
+
`${borrowIncentiveIds.borrowIncentivePkg}::user::redeem_rewards`,
|
|
3812
|
+
[
|
|
3813
|
+
borrowIncentiveIds.incentivePools,
|
|
3814
|
+
borrowIncentiveIds.incentiveAccounts,
|
|
3815
|
+
obligaionKey,
|
|
3816
|
+
obligationId,
|
|
3817
|
+
SUI_CLOCK_OBJECT_ID4
|
|
3818
|
+
],
|
|
3819
|
+
[rewardType]
|
|
3820
|
+
);
|
|
3821
|
+
}
|
|
3822
|
+
};
|
|
3823
|
+
};
|
|
3824
|
+
var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
|
|
3825
|
+
return {
|
|
3826
|
+
stakeObligationQuick: async (coinName, obligation, obligationKey) => {
|
|
3827
|
+
const {
|
|
3828
|
+
obligationId: obligationArg,
|
|
3829
|
+
obligationKey: obligationtKeyArg,
|
|
3830
|
+
obligationLocked
|
|
3831
|
+
} = await requireObligationInfo2(
|
|
3832
|
+
builder,
|
|
3833
|
+
txBlock,
|
|
3834
|
+
obligation,
|
|
3835
|
+
obligationKey
|
|
3836
|
+
);
|
|
3837
|
+
const unstakeObligationBeforeStake = !!txBlock.txBlock.blockData.transactions.find(
|
|
3838
|
+
(txn) => txn.kind === "MoveCall" && txn.target === `${builder.address.get("borrowIncentive.id")}::user::unstake`
|
|
3839
|
+
);
|
|
3840
|
+
if (!obligationLocked || unstakeObligationBeforeStake) {
|
|
3841
|
+
txBlock.stakeObligation(obligationArg, obligationtKeyArg, coinName);
|
|
3842
|
+
}
|
|
3843
|
+
},
|
|
3844
|
+
unstakeObligationQuick: async (coinName, obligation, obligationKey) => {
|
|
3845
|
+
const {
|
|
3846
|
+
obligationId: obligationArg,
|
|
3847
|
+
obligationKey: obligationtKeyArg,
|
|
3848
|
+
obligationLocked
|
|
3849
|
+
} = await requireObligationInfo2(
|
|
3850
|
+
builder,
|
|
3851
|
+
txBlock,
|
|
3852
|
+
obligation,
|
|
3853
|
+
obligationKey
|
|
3854
|
+
);
|
|
3855
|
+
if (obligationLocked) {
|
|
3856
|
+
txBlock.unstakeObligation(obligationArg, obligationtKeyArg, coinName);
|
|
3857
|
+
}
|
|
3858
|
+
},
|
|
3859
|
+
claimBorrowIncentiveQuick: async (coinName, obligation, obligationKey) => {
|
|
3860
|
+
const {
|
|
3861
|
+
obligationId: obligationArg,
|
|
3862
|
+
obligationKey: obligationtKeyArg
|
|
3863
|
+
} = await requireObligationInfo2(
|
|
3864
|
+
builder,
|
|
3865
|
+
txBlock,
|
|
3866
|
+
obligation,
|
|
3867
|
+
obligationKey
|
|
3868
|
+
);
|
|
3869
|
+
return txBlock.claimBorrowIncentive(
|
|
3870
|
+
obligationArg,
|
|
3871
|
+
obligationtKeyArg,
|
|
3872
|
+
coinName
|
|
3873
|
+
);
|
|
3874
|
+
}
|
|
3875
|
+
};
|
|
3876
|
+
};
|
|
3877
|
+
var newBorrowIncentiveTxBlock = (builder, initTxBlock) => {
|
|
3878
|
+
const txBlock = initTxBlock instanceof TransactionBlock3 ? new SuiKitTxBlock5(initTxBlock) : initTxBlock ? initTxBlock : new SuiKitTxBlock5();
|
|
3879
|
+
const normalMethod = generateBorrowIncentiveNormalMethod({
|
|
3880
|
+
builder,
|
|
3881
|
+
txBlock
|
|
3882
|
+
});
|
|
3883
|
+
const normalTxBlock = new Proxy(txBlock, {
|
|
3884
|
+
get: (target, prop) => {
|
|
3885
|
+
if (prop in normalMethod) {
|
|
3886
|
+
return Reflect.get(normalMethod, prop);
|
|
3887
|
+
}
|
|
3888
|
+
return Reflect.get(target, prop);
|
|
3889
|
+
}
|
|
3890
|
+
});
|
|
3891
|
+
const quickMethod = generateBorrowIncentiveQuickMethod({
|
|
3892
|
+
builder,
|
|
3893
|
+
txBlock: normalTxBlock
|
|
3894
|
+
});
|
|
3895
|
+
return new Proxy(normalTxBlock, {
|
|
3896
|
+
get: (target, prop) => {
|
|
3897
|
+
if (prop in quickMethod) {
|
|
3898
|
+
return Reflect.get(quickMethod, prop);
|
|
3899
|
+
}
|
|
3900
|
+
return Reflect.get(target, prop);
|
|
3901
|
+
}
|
|
3902
|
+
});
|
|
3903
|
+
};
|
|
3904
|
+
|
|
3403
3905
|
// src/builders/index.ts
|
|
3404
3906
|
var newScallopTxBlock = (builder, initTxBlock) => {
|
|
3405
|
-
const
|
|
3907
|
+
const borrowIncentiveTxBlock = newBorrowIncentiveTxBlock(
|
|
3908
|
+
builder,
|
|
3909
|
+
initTxBlock
|
|
3910
|
+
);
|
|
3911
|
+
const spoolTxBlock = newSpoolTxBlock(builder, borrowIncentiveTxBlock);
|
|
3406
3912
|
const coreTxBlock = newCoreTxBlock(builder, spoolTxBlock);
|
|
3407
3913
|
return new Proxy(coreTxBlock, {
|
|
3408
3914
|
get: (target, prop) => {
|
|
3409
|
-
if (prop in
|
|
3915
|
+
if (prop in borrowIncentiveTxBlock) {
|
|
3916
|
+
return Reflect.get(borrowIncentiveTxBlock, prop);
|
|
3917
|
+
} else if (prop in spoolTxBlock) {
|
|
3410
3918
|
return Reflect.get(spoolTxBlock, prop);
|
|
3411
3919
|
}
|
|
3412
3920
|
return Reflect.get(target, prop);
|
|
@@ -3630,8 +4138,8 @@ var ScallopClient = class {
|
|
|
3630
4138
|
* @param stakeMarketCoinName - Support stake market coin.
|
|
3631
4139
|
* @return Reward pool data.
|
|
3632
4140
|
*/
|
|
3633
|
-
async
|
|
3634
|
-
return await this.query.
|
|
4141
|
+
async getStakeRewardPool(stakeMarketCoinName) {
|
|
4142
|
+
return await this.query.getStakeRewardPool(stakeMarketCoinName);
|
|
3635
4143
|
}
|
|
3636
4144
|
async openObligation(sign = true) {
|
|
3637
4145
|
const txBlock = this.builder.createTxBlock();
|
|
@@ -3903,11 +4411,84 @@ var ScallopClient = class {
|
|
|
3903
4411
|
const txBlock = this.builder.createTxBlock();
|
|
3904
4412
|
const sender = walletAddress || this.walletAddress;
|
|
3905
4413
|
txBlock.setSender(sender);
|
|
3906
|
-
const
|
|
4414
|
+
const rewardCoins = await txBlock.claimQuick(
|
|
3907
4415
|
stakeMarketCoinName,
|
|
3908
4416
|
stakeAccountId
|
|
3909
4417
|
);
|
|
3910
|
-
txBlock.transferObjects(
|
|
4418
|
+
txBlock.transferObjects(rewardCoins, sender);
|
|
4419
|
+
if (sign) {
|
|
4420
|
+
return await this.suiKit.signAndSendTxn(
|
|
4421
|
+
txBlock
|
|
4422
|
+
);
|
|
4423
|
+
} else {
|
|
4424
|
+
return txBlock.txBlock;
|
|
4425
|
+
}
|
|
4426
|
+
}
|
|
4427
|
+
/* ==================== Borrow Incentive Method ==================== */
|
|
4428
|
+
/**
|
|
4429
|
+
* stake obligaion.
|
|
4430
|
+
*
|
|
4431
|
+
* @param sign - Decide to directly sign the transaction or return the transaction block.
|
|
4432
|
+
* @param obligaionId - The obligation account object.
|
|
4433
|
+
* @param obligaionKeyId - The obligation key account object.
|
|
4434
|
+
* @param walletAddress - The wallet address of the owner.
|
|
4435
|
+
* @return Transaction block response or transaction block
|
|
4436
|
+
*/
|
|
4437
|
+
async stakeObligation(coinName, obligaionId, obligaionKeyId, sign = true, walletAddress) {
|
|
4438
|
+
const txBlock = this.builder.createTxBlock();
|
|
4439
|
+
const sender = walletAddress || this.walletAddress;
|
|
4440
|
+
txBlock.setSender(sender);
|
|
4441
|
+
await txBlock.stakeObligationQuick(coinName, obligaionId, obligaionKeyId);
|
|
4442
|
+
if (sign) {
|
|
4443
|
+
return await this.suiKit.signAndSendTxn(
|
|
4444
|
+
txBlock
|
|
4445
|
+
);
|
|
4446
|
+
} else {
|
|
4447
|
+
return txBlock.txBlock;
|
|
4448
|
+
}
|
|
4449
|
+
}
|
|
4450
|
+
/**
|
|
4451
|
+
* unstake obligaion.
|
|
4452
|
+
*
|
|
4453
|
+
* @param sign - Decide to directly sign the transaction or return the transaction block.
|
|
4454
|
+
* @param obligaionId - The obligation account object.
|
|
4455
|
+
* @param obligaionKeyId - The obligation key account object.
|
|
4456
|
+
* @param walletAddress - The wallet address of the owner.
|
|
4457
|
+
* @return Transaction block response or transaction block
|
|
4458
|
+
*/
|
|
4459
|
+
async unstakeObligation(coinName, obligaionId, obligaionKeyId, sign = true, walletAddress) {
|
|
4460
|
+
const txBlock = this.builder.createTxBlock();
|
|
4461
|
+
const sender = walletAddress || this.walletAddress;
|
|
4462
|
+
txBlock.setSender(sender);
|
|
4463
|
+
await txBlock.unstakeObligationQuick(coinName, obligaionId, obligaionKeyId);
|
|
4464
|
+
if (sign) {
|
|
4465
|
+
return await this.suiKit.signAndSendTxn(
|
|
4466
|
+
txBlock
|
|
4467
|
+
);
|
|
4468
|
+
} else {
|
|
4469
|
+
return txBlock.txBlock;
|
|
4470
|
+
}
|
|
4471
|
+
}
|
|
4472
|
+
/**
|
|
4473
|
+
* unstake market coin from the specific spool.
|
|
4474
|
+
*
|
|
4475
|
+
* @param marketCoinName - Types of mak coin.
|
|
4476
|
+
* @param amount - The amount of coins would deposit.
|
|
4477
|
+
* @param sign - Decide to directly sign the transaction or return the transaction block.
|
|
4478
|
+
* @param accountId - The stake account object.
|
|
4479
|
+
* @param walletAddress - The wallet address of the owner.
|
|
4480
|
+
* @return Transaction block response or transaction block
|
|
4481
|
+
*/
|
|
4482
|
+
async claimBorrowIncentive(coinName, obligaionId, obligaionKeyId, sign = true, walletAddress) {
|
|
4483
|
+
const txBlock = this.builder.createTxBlock();
|
|
4484
|
+
const sender = walletAddress || this.walletAddress;
|
|
4485
|
+
txBlock.setSender(sender);
|
|
4486
|
+
const rewardCoin = await txBlock.claimBorrowIncentiveQuick(
|
|
4487
|
+
coinName,
|
|
4488
|
+
obligaionId,
|
|
4489
|
+
obligaionKeyId
|
|
4490
|
+
);
|
|
4491
|
+
txBlock.transferObjects([rewardCoin], sender);
|
|
3911
4492
|
if (sign) {
|
|
3912
4493
|
return await this.suiKit.signAndSendTxn(
|
|
3913
4494
|
txBlock
|
|
@@ -4020,12 +4601,14 @@ export {
|
|
|
4020
4601
|
ADDRESSES_ID,
|
|
4021
4602
|
API_BASE_URL,
|
|
4022
4603
|
PROTOCOL_OBJECT_ID,
|
|
4604
|
+
SUPPORT_BORROW_INCENTIVE_POOLS,
|
|
4605
|
+
SUPPORT_BORROW_INCENTIVE_REWARDS,
|
|
4023
4606
|
SUPPORT_COLLATERALS,
|
|
4024
4607
|
SUPPORT_ORACLES,
|
|
4025
4608
|
SUPPORT_PACKAGES,
|
|
4026
4609
|
SUPPORT_POOLS,
|
|
4027
|
-
SUPPORT_REWARD_POOLS,
|
|
4028
4610
|
SUPPORT_SPOOLS,
|
|
4611
|
+
SUPPORT_SPOOLS_REWARDS,
|
|
4029
4612
|
Scallop,
|
|
4030
4613
|
ScallopAddress,
|
|
4031
4614
|
ScallopBuilder,
|
|
@@ -4033,10 +4616,11 @@ export {
|
|
|
4033
4616
|
ScallopQuery,
|
|
4034
4617
|
ScallopUtils,
|
|
4035
4618
|
assetCoins,
|
|
4619
|
+
borrowIncentiveRewardCoins,
|
|
4036
4620
|
coinDecimals,
|
|
4037
4621
|
coinIds,
|
|
4038
4622
|
marketCoins,
|
|
4039
|
-
|
|
4623
|
+
spoolRewardCoins,
|
|
4040
4624
|
stakeMarketCoins,
|
|
4041
4625
|
voloCoinIds,
|
|
4042
4626
|
wormholeCoinIds
|