@scallop-io/sui-scallop-sdk 0.44.1 → 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 +5 -3
- package/dist/constants/enum.d.ts +4 -2
- package/dist/index.js +843 -228
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +803 -192
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopClient.d.ts +33 -2
- package/dist/models/scallopQuery.d.ts +36 -10
- package/dist/models/scallopUtils.d.ts +12 -4
- package/dist/queries/borrowIncentiveQuery.d.ts +24 -0
- package/dist/queries/coreQuery.d.ts +12 -0
- package/dist/queries/index.d.ts +1 -0
- package/dist/queries/portfolioQuery.d.ts +1 -0
- package/dist/queries/spoolQuery.d.ts +13 -5
- package/dist/types/address.d.ts +10 -2
- 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 +9 -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 +15 -1
- package/package.json +12 -12
- 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 +6 -1
- package/src/constants/enum.ts +18 -2
- package/src/models/scallopAddress.ts +47 -0
- package/src/models/scallopClient.ts +104 -2
- package/src/models/scallopQuery.ts +48 -14
- package/src/models/scallopUtils.ts +53 -15
- 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 +10 -2
- 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 +13 -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 +59 -9
- package/dist/utils/oracle.d.ts +0 -14
- package/src/utils/oracle.ts +0 -36
package/dist/index.js
CHANGED
|
@@ -33,12 +33,14 @@ __export(src_exports, {
|
|
|
33
33
|
ADDRESSES_ID: () => ADDRESSES_ID,
|
|
34
34
|
API_BASE_URL: () => API_BASE_URL,
|
|
35
35
|
PROTOCOL_OBJECT_ID: () => PROTOCOL_OBJECT_ID,
|
|
36
|
+
SUPPORT_BORROW_INCENTIVE_POOLS: () => SUPPORT_BORROW_INCENTIVE_POOLS,
|
|
37
|
+
SUPPORT_BORROW_INCENTIVE_REWARDS: () => SUPPORT_BORROW_INCENTIVE_REWARDS,
|
|
36
38
|
SUPPORT_COLLATERALS: () => SUPPORT_COLLATERALS,
|
|
37
39
|
SUPPORT_ORACLES: () => SUPPORT_ORACLES,
|
|
38
40
|
SUPPORT_PACKAGES: () => SUPPORT_PACKAGES,
|
|
39
41
|
SUPPORT_POOLS: () => SUPPORT_POOLS,
|
|
40
|
-
SUPPORT_REWARD_POOLS: () => SUPPORT_REWARD_POOLS,
|
|
41
42
|
SUPPORT_SPOOLS: () => SUPPORT_SPOOLS,
|
|
43
|
+
SUPPORT_SPOOLS_REWARDS: () => SUPPORT_SPOOLS_REWARDS,
|
|
42
44
|
Scallop: () => Scallop,
|
|
43
45
|
ScallopAddress: () => ScallopAddress,
|
|
44
46
|
ScallopBuilder: () => ScallopBuilder,
|
|
@@ -46,11 +48,13 @@ __export(src_exports, {
|
|
|
46
48
|
ScallopQuery: () => ScallopQuery,
|
|
47
49
|
ScallopUtils: () => ScallopUtils,
|
|
48
50
|
assetCoins: () => assetCoins,
|
|
51
|
+
borrowIncentiveRewardCoins: () => borrowIncentiveRewardCoins,
|
|
49
52
|
coinDecimals: () => coinDecimals,
|
|
50
53
|
coinIds: () => coinIds,
|
|
51
54
|
marketCoins: () => marketCoins,
|
|
52
|
-
|
|
55
|
+
spoolRewardCoins: () => spoolRewardCoins,
|
|
53
56
|
stakeMarketCoins: () => stakeMarketCoins,
|
|
57
|
+
voloCoinIds: () => voloCoinIds,
|
|
54
58
|
wormholeCoinIds: () => wormholeCoinIds
|
|
55
59
|
});
|
|
56
60
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -69,7 +73,8 @@ var SUPPORT_POOLS = [
|
|
|
69
73
|
"sol",
|
|
70
74
|
"cetus",
|
|
71
75
|
"afsui",
|
|
72
|
-
"hasui"
|
|
76
|
+
"hasui",
|
|
77
|
+
"vsui"
|
|
73
78
|
];
|
|
74
79
|
var SUPPORT_COLLATERALS = [
|
|
75
80
|
"eth",
|
|
@@ -81,10 +86,13 @@ var SUPPORT_COLLATERALS = [
|
|
|
81
86
|
"sol",
|
|
82
87
|
"cetus",
|
|
83
88
|
"afsui",
|
|
84
|
-
"hasui"
|
|
89
|
+
"hasui",
|
|
90
|
+
"vsui"
|
|
85
91
|
];
|
|
86
92
|
var SUPPORT_SPOOLS = ["ssui", "susdc", "susdt"];
|
|
87
|
-
var
|
|
93
|
+
var SUPPORT_SPOOLS_REWARDS = ["sui"];
|
|
94
|
+
var SUPPORT_BORROW_INCENTIVE_POOLS = ["sui", "usdc"];
|
|
95
|
+
var SUPPORT_BORROW_INCENTIVE_REWARDS = ["sui"];
|
|
88
96
|
var SUPPORT_ORACLES = ["supra", "switchboard", "pyth"];
|
|
89
97
|
var SUPPORT_PACKAGES = [
|
|
90
98
|
"coinDecimalsRegistry",
|
|
@@ -113,6 +121,7 @@ var coinDecimals = {
|
|
|
113
121
|
cetus: 9,
|
|
114
122
|
afsui: 9,
|
|
115
123
|
hasui: 9,
|
|
124
|
+
vsui: 9,
|
|
116
125
|
seth: 8,
|
|
117
126
|
sbtc: 8,
|
|
118
127
|
susdc: 6,
|
|
@@ -122,7 +131,8 @@ var coinDecimals = {
|
|
|
122
131
|
ssol: 8,
|
|
123
132
|
scetus: 9,
|
|
124
133
|
safsui: 9,
|
|
125
|
-
shasui: 9
|
|
134
|
+
shasui: 9,
|
|
135
|
+
svsui: 9
|
|
126
136
|
};
|
|
127
137
|
var assetCoins = {
|
|
128
138
|
eth: "eth",
|
|
@@ -134,7 +144,8 @@ var assetCoins = {
|
|
|
134
144
|
sol: "sol",
|
|
135
145
|
cetus: "cetus",
|
|
136
146
|
afsui: "afsui",
|
|
137
|
-
hasui: "hasui"
|
|
147
|
+
hasui: "hasui",
|
|
148
|
+
vsui: "vsui"
|
|
138
149
|
};
|
|
139
150
|
var marketCoins = {
|
|
140
151
|
seth: "seth",
|
|
@@ -146,18 +157,23 @@ var marketCoins = {
|
|
|
146
157
|
ssol: "ssol",
|
|
147
158
|
scetus: "scetus",
|
|
148
159
|
safsui: "safsui",
|
|
149
|
-
shasui: "shasui"
|
|
160
|
+
shasui: "shasui",
|
|
161
|
+
svsui: "svsui"
|
|
150
162
|
};
|
|
151
163
|
var stakeMarketCoins = {
|
|
152
164
|
ssui: "ssui",
|
|
153
165
|
susdc: "susdc",
|
|
154
166
|
susdt: "susdt"
|
|
155
167
|
};
|
|
156
|
-
var
|
|
168
|
+
var spoolRewardCoins = {
|
|
157
169
|
ssui: "sui",
|
|
158
170
|
susdc: "sui",
|
|
159
171
|
susdt: "sui"
|
|
160
172
|
};
|
|
173
|
+
var borrowIncentiveRewardCoins = {
|
|
174
|
+
sui: "sui",
|
|
175
|
+
usdc: "sui"
|
|
176
|
+
};
|
|
161
177
|
var coinIds = {
|
|
162
178
|
sui: "0x0000000000000000000000000000000000000000000000000000000000000002",
|
|
163
179
|
eth: "0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5",
|
|
@@ -168,7 +184,8 @@ var coinIds = {
|
|
|
168
184
|
sol: "0xb7844e289a8410e50fb3ca48d69eb9cf29e27d223ef90353fe1bd8e27ff8f3f8",
|
|
169
185
|
cetus: "0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b",
|
|
170
186
|
afsui: "0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc",
|
|
171
|
-
hasui: "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d"
|
|
187
|
+
hasui: "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d",
|
|
188
|
+
vsui: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55"
|
|
172
189
|
};
|
|
173
190
|
var wormholeCoinIds = {
|
|
174
191
|
eth: "0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5",
|
|
@@ -178,9 +195,12 @@ var wormholeCoinIds = {
|
|
|
178
195
|
apt: "0x3a5143bb1196e3bcdfab6203d1683ae29edd26294fc8bfeafe4aaa9d2704df37",
|
|
179
196
|
sol: "0xb7844e289a8410e50fb3ca48d69eb9cf29e27d223ef90353fe1bd8e27ff8f3f8"
|
|
180
197
|
};
|
|
198
|
+
var voloCoinIds = {
|
|
199
|
+
vsui: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55"
|
|
200
|
+
};
|
|
181
201
|
|
|
182
202
|
// src/models/scallop.ts
|
|
183
|
-
var
|
|
203
|
+
var import_sui_kit10 = require("@scallop-io/sui-kit");
|
|
184
204
|
|
|
185
205
|
// src/models/scallopAddress.ts
|
|
186
206
|
var import_axios = __toESM(require("axios"));
|
|
@@ -191,6 +211,7 @@ var EMPTY_ADDRESSES = {
|
|
|
191
211
|
market: "",
|
|
192
212
|
adminCap: "",
|
|
193
213
|
coinDecimalsRegistry: "",
|
|
214
|
+
obligationAccessStore: "",
|
|
194
215
|
coins: {
|
|
195
216
|
btc: {
|
|
196
217
|
id: "",
|
|
@@ -256,6 +277,45 @@ var EMPTY_ADDRESSES = {
|
|
|
256
277
|
feedObject: ""
|
|
257
278
|
}
|
|
258
279
|
}
|
|
280
|
+
},
|
|
281
|
+
afsui: {
|
|
282
|
+
id: "",
|
|
283
|
+
metaData: "",
|
|
284
|
+
treasury: "",
|
|
285
|
+
oracle: {
|
|
286
|
+
supra: "",
|
|
287
|
+
switchboard: "",
|
|
288
|
+
pyth: {
|
|
289
|
+
feed: "",
|
|
290
|
+
feedObject: ""
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
},
|
|
294
|
+
hasui: {
|
|
295
|
+
id: "",
|
|
296
|
+
metaData: "",
|
|
297
|
+
treasury: "",
|
|
298
|
+
oracle: {
|
|
299
|
+
supra: "",
|
|
300
|
+
switchboard: "",
|
|
301
|
+
pyth: {
|
|
302
|
+
feed: "",
|
|
303
|
+
feedObject: ""
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
},
|
|
307
|
+
vsui: {
|
|
308
|
+
id: "",
|
|
309
|
+
metaData: "",
|
|
310
|
+
treasury: "",
|
|
311
|
+
oracle: {
|
|
312
|
+
supra: "",
|
|
313
|
+
switchboard: "",
|
|
314
|
+
pyth: {
|
|
315
|
+
feed: "",
|
|
316
|
+
feedObject: ""
|
|
317
|
+
}
|
|
318
|
+
}
|
|
259
319
|
}
|
|
260
320
|
},
|
|
261
321
|
oracles: {
|
|
@@ -335,6 +395,13 @@ var EMPTY_ADDRESSES = {
|
|
|
335
395
|
rewardPoolId: ""
|
|
336
396
|
}
|
|
337
397
|
}
|
|
398
|
+
},
|
|
399
|
+
borrowIncentive: {
|
|
400
|
+
id: "",
|
|
401
|
+
adminCap: "",
|
|
402
|
+
query: "",
|
|
403
|
+
incentivePools: "",
|
|
404
|
+
incentiveAccounts: ""
|
|
338
405
|
}
|
|
339
406
|
};
|
|
340
407
|
var ScallopAddress = class {
|
|
@@ -638,43 +705,33 @@ var ScallopAddress = class {
|
|
|
638
705
|
};
|
|
639
706
|
|
|
640
707
|
// src/models/scallopClient.ts
|
|
641
|
-
var
|
|
642
|
-
var
|
|
708
|
+
var import_utils17 = require("@mysten/sui.js/utils");
|
|
709
|
+
var import_sui_kit9 = require("@scallop-io/sui-kit");
|
|
643
710
|
|
|
644
711
|
// src/models/scallopUtils.ts
|
|
645
|
-
var
|
|
646
|
-
var
|
|
712
|
+
var import_utils7 = require("@mysten/sui.js/utils");
|
|
713
|
+
var import_sui_kit4 = require("@scallop-io/sui-kit");
|
|
647
714
|
var import_pyth_sui_js = require("@pythnetwork/pyth-sui-js");
|
|
648
715
|
|
|
649
716
|
// src/models/scallopQuery.ts
|
|
650
|
-
var
|
|
717
|
+
var import_sui_kit3 = require("@scallop-io/sui-kit");
|
|
651
718
|
|
|
652
719
|
// src/queries/coreQuery.ts
|
|
653
720
|
var import_sui_kit = require("@scallop-io/sui-kit");
|
|
654
721
|
var import_bignumber2 = __toESM(require("bignumber.js"));
|
|
655
722
|
|
|
656
|
-
// src/utils/
|
|
657
|
-
var
|
|
658
|
-
const
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
const assetCoinName = assetCoinNames.find((assetCoinName2) => {
|
|
662
|
-
return address.get(`core.coins.${assetCoinName2}.oracle.pyth.feed`) === feed.id;
|
|
663
|
-
});
|
|
664
|
-
if (assetCoinName) {
|
|
665
|
-
const price = feed.price.price * 10 ** feed.price.expo;
|
|
666
|
-
return {
|
|
667
|
-
coinName: assetCoinName,
|
|
668
|
-
price,
|
|
669
|
-
publishTime: Number(feed.price.publishTime) * 10 ** 3
|
|
670
|
-
};
|
|
671
|
-
} else {
|
|
672
|
-
throw new Error("Invalid feed id");
|
|
723
|
+
// src/utils/builder.ts
|
|
724
|
+
var requireSender = (txBlock) => {
|
|
725
|
+
const sender = txBlock.blockData.sender;
|
|
726
|
+
if (!sender) {
|
|
727
|
+
throw new Error("Sender is required");
|
|
673
728
|
}
|
|
729
|
+
return sender;
|
|
674
730
|
};
|
|
675
731
|
|
|
676
732
|
// src/utils/query.ts
|
|
677
733
|
var import_bignumber = __toESM(require("bignumber.js"));
|
|
734
|
+
var import_utils = require("@mysten/sui.js/utils");
|
|
678
735
|
var parseOriginMarketPoolData = (originMarketPoolData) => {
|
|
679
736
|
return {
|
|
680
737
|
coinType: "0x" + originMarketPoolData.type.name,
|
|
@@ -801,48 +858,48 @@ var calculateMarketCollateralData = (utils, parsedMarketCollateralData) => {
|
|
|
801
858
|
depositCoin: depositCoin.toNumber()
|
|
802
859
|
};
|
|
803
860
|
};
|
|
804
|
-
var
|
|
861
|
+
var parseOriginSpoolData = (originSpoolData) => {
|
|
805
862
|
return {
|
|
806
|
-
stakeType: "0x" +
|
|
807
|
-
maxPoint: Number(
|
|
808
|
-
distributedPoint: Number(
|
|
809
|
-
pointPerPeriod: Number(
|
|
810
|
-
period: Number(
|
|
811
|
-
maxStake: Number(
|
|
812
|
-
staked: Number(
|
|
813
|
-
index: Number(
|
|
814
|
-
createdAt: Number(
|
|
815
|
-
lastUpdate: Number(
|
|
863
|
+
stakeType: "0x" + originSpoolData.stakeType.fields.name,
|
|
864
|
+
maxPoint: Number(originSpoolData.maxDistributedPoint),
|
|
865
|
+
distributedPoint: Number(originSpoolData.distributedPoint),
|
|
866
|
+
pointPerPeriod: Number(originSpoolData.distributedPointPerPeriod),
|
|
867
|
+
period: Number(originSpoolData.pointDistributionTime),
|
|
868
|
+
maxStake: Number(originSpoolData.maxStake),
|
|
869
|
+
staked: Number(originSpoolData.stakes),
|
|
870
|
+
index: Number(originSpoolData.index),
|
|
871
|
+
createdAt: Number(originSpoolData.createdAt),
|
|
872
|
+
lastUpdate: Number(originSpoolData.lastUpdate)
|
|
816
873
|
};
|
|
817
874
|
};
|
|
818
|
-
var
|
|
875
|
+
var calculateSpoolData = (parsedSpoolData, stakeMarketCoinPrice, stakeMarketCoinDecimal) => {
|
|
819
876
|
const baseIndexRate = 1e9;
|
|
820
877
|
const distributedPointPerSec = (0, import_bignumber.default)(
|
|
821
|
-
|
|
822
|
-
).dividedBy(
|
|
823
|
-
const pointPerSec = (0, import_bignumber.default)(
|
|
824
|
-
|
|
878
|
+
parsedSpoolData.pointPerPeriod
|
|
879
|
+
).dividedBy(parsedSpoolData.period);
|
|
880
|
+
const pointPerSec = (0, import_bignumber.default)(parsedSpoolData.pointPerPeriod).dividedBy(
|
|
881
|
+
parsedSpoolData.period
|
|
825
882
|
);
|
|
826
|
-
const remainingPeriod = (0, import_bignumber.default)(
|
|
827
|
-
const startDate =
|
|
828
|
-
const endDate = remainingPeriod.plus(
|
|
883
|
+
const remainingPeriod = (0, import_bignumber.default)(parsedSpoolData.maxPoint).minus(parsedSpoolData.distributedPoint).dividedBy(pointPerSec);
|
|
884
|
+
const startDate = parsedSpoolData.createdAt;
|
|
885
|
+
const endDate = remainingPeriod.plus(parsedSpoolData.lastUpdate).integerValue().toNumber();
|
|
829
886
|
const timeDelta = (0, import_bignumber.default)(
|
|
830
|
-
Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) -
|
|
831
|
-
).dividedBy(
|
|
832
|
-
const remainingPoints = (0, import_bignumber.default)(
|
|
833
|
-
|
|
887
|
+
Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) - parsedSpoolData.lastUpdate
|
|
888
|
+
).dividedBy(parsedSpoolData.period).toFixed(0);
|
|
889
|
+
const remainingPoints = (0, import_bignumber.default)(parsedSpoolData.maxPoint).minus(
|
|
890
|
+
parsedSpoolData.distributedPoint
|
|
834
891
|
);
|
|
835
892
|
const accumulatedPoints = import_bignumber.default.minimum(
|
|
836
|
-
(0, import_bignumber.default)(timeDelta).multipliedBy(
|
|
893
|
+
(0, import_bignumber.default)(timeDelta).multipliedBy(parsedSpoolData.pointPerPeriod),
|
|
837
894
|
remainingPoints
|
|
838
895
|
);
|
|
839
|
-
const currentPointIndex = (0, import_bignumber.default)(
|
|
840
|
-
accumulatedPoints.dividedBy(
|
|
896
|
+
const currentPointIndex = (0, import_bignumber.default)(parsedSpoolData.index).plus(
|
|
897
|
+
accumulatedPoints.dividedBy(parsedSpoolData.staked).isFinite() ? (0, import_bignumber.default)(baseIndexRate).multipliedBy(accumulatedPoints).dividedBy(parsedSpoolData.staked) : 0
|
|
841
898
|
);
|
|
842
899
|
const currentTotalDistributedPoint = (0, import_bignumber.default)(
|
|
843
|
-
|
|
900
|
+
parsedSpoolData.distributedPoint
|
|
844
901
|
).plus(accumulatedPoints);
|
|
845
|
-
const stakedAmount = (0, import_bignumber.default)(
|
|
902
|
+
const stakedAmount = (0, import_bignumber.default)(parsedSpoolData.staked);
|
|
846
903
|
const stakedCoin = stakedAmount.shiftedBy(-1 * stakeMarketCoinDecimal);
|
|
847
904
|
const stakedValue = stakedCoin.multipliedBy(stakeMarketCoinPrice);
|
|
848
905
|
return {
|
|
@@ -857,35 +914,39 @@ var calculateStakePoolData = (parsedStakePoolData, stakeMarketCoinPrice, stakeMa
|
|
|
857
914
|
stakedValue: stakedValue.toNumber()
|
|
858
915
|
};
|
|
859
916
|
};
|
|
860
|
-
var
|
|
917
|
+
var parseOriginSpoolRewardPoolData = (originSpoolRewardPoolData) => {
|
|
861
918
|
return {
|
|
862
|
-
claimedRewards: Number(
|
|
863
|
-
exchangeRateNumerator: Number(
|
|
919
|
+
claimedRewards: Number(originSpoolRewardPoolData.claimed_rewards),
|
|
920
|
+
exchangeRateNumerator: Number(
|
|
921
|
+
originSpoolRewardPoolData.exchange_rate_numerator
|
|
922
|
+
),
|
|
864
923
|
exchangeRateDenominator: Number(
|
|
865
|
-
|
|
924
|
+
originSpoolRewardPoolData.exchange_rate_denominator
|
|
866
925
|
),
|
|
867
|
-
rewards: Number(
|
|
868
|
-
spoolId: String(
|
|
926
|
+
rewards: Number(originSpoolRewardPoolData.rewards),
|
|
927
|
+
spoolId: String(originSpoolRewardPoolData.spool_id)
|
|
869
928
|
};
|
|
870
929
|
};
|
|
871
|
-
var
|
|
930
|
+
var calculateSpoolRewardPoolData = (parsedSpoolData, parsedSpoolRewardPoolData, calculatedSpoolData, rewardCoinPrice, rewardCoinDecimal) => {
|
|
872
931
|
const rateYearFactor = 365 * 24 * 60 * 60;
|
|
873
|
-
const rewardPerSec = (0, import_bignumber.default)(
|
|
874
|
-
const totalRewardAmount = (0, import_bignumber.default)(
|
|
932
|
+
const rewardPerSec = (0, import_bignumber.default)(calculatedSpoolData.distributedPointPerSec).multipliedBy(parsedSpoolRewardPoolData.exchangeRateNumerator).dividedBy(parsedSpoolRewardPoolData.exchangeRateDenominator);
|
|
933
|
+
const totalRewardAmount = (0, import_bignumber.default)(parsedSpoolData.maxPoint).multipliedBy(parsedSpoolRewardPoolData.exchangeRateNumerator).dividedBy(parsedSpoolRewardPoolData.exchangeRateDenominator);
|
|
875
934
|
const totalRewardCoin = totalRewardAmount.shiftedBy(-1 * rewardCoinDecimal);
|
|
876
935
|
const totalRewardValue = totalRewardCoin.multipliedBy(rewardCoinPrice);
|
|
877
|
-
const remaindRewardAmount = (0, import_bignumber.default)(
|
|
936
|
+
const remaindRewardAmount = (0, import_bignumber.default)(parsedSpoolRewardPoolData.rewards);
|
|
878
937
|
const remaindRewardCoin = remaindRewardAmount.shiftedBy(
|
|
879
938
|
-1 * rewardCoinDecimal
|
|
880
939
|
);
|
|
881
940
|
const remaindRewardValue = remaindRewardCoin.multipliedBy(rewardCoinPrice);
|
|
882
|
-
const claimedRewardAmount = (0, import_bignumber.default)(
|
|
941
|
+
const claimedRewardAmount = (0, import_bignumber.default)(
|
|
942
|
+
parsedSpoolRewardPoolData.claimedRewards
|
|
943
|
+
);
|
|
883
944
|
const claimedRewardCoin = claimedRewardAmount.shiftedBy(
|
|
884
945
|
-1 * rewardCoinDecimal
|
|
885
946
|
);
|
|
886
947
|
const claimedRewardValue = claimedRewardCoin.multipliedBy(rewardCoinPrice);
|
|
887
948
|
const rewardValueForYear = (0, import_bignumber.default)(rewardPerSec).shiftedBy(-1 * rewardCoinDecimal).multipliedBy(rateYearFactor).multipliedBy(rewardCoinPrice);
|
|
888
|
-
const rewardRate = rewardValueForYear.dividedBy(
|
|
949
|
+
const rewardRate = rewardValueForYear.dividedBy(calculatedSpoolData.stakedValue).isFinite() ? rewardValueForYear.dividedBy(calculatedSpoolData.stakedValue).toNumber() : Infinity;
|
|
889
950
|
return {
|
|
890
951
|
rewardApr: rewardRate,
|
|
891
952
|
totalRewardAmount: totalRewardAmount.toNumber(),
|
|
@@ -897,9 +958,133 @@ var calculateRewardPoolData = (parsedStakePoolData, parsedRewardPoolData, calcul
|
|
|
897
958
|
claimedRewardAmount: claimedRewardAmount.toNumber(),
|
|
898
959
|
claimedRewardCoin: claimedRewardCoin.toNumber(),
|
|
899
960
|
claimedRewardValue: claimedRewardValue.toNumber(),
|
|
900
|
-
rewardPerSec: rewardPerSec.toNumber()
|
|
901
|
-
|
|
902
|
-
|
|
961
|
+
rewardPerSec: rewardPerSec.toNumber()
|
|
962
|
+
};
|
|
963
|
+
};
|
|
964
|
+
var parseOriginBorrowIncentivePoolData = (originBorrowIncentivePoolData) => {
|
|
965
|
+
return {
|
|
966
|
+
poolType: (0, import_utils.normalizeStructTag)(originBorrowIncentivePoolData.pool_type.name),
|
|
967
|
+
maxPoint: Number(originBorrowIncentivePoolData.max_distributed_point),
|
|
968
|
+
distributedPoint: Number(originBorrowIncentivePoolData.distributed_point),
|
|
969
|
+
pointPerPeriod: Number(
|
|
970
|
+
originBorrowIncentivePoolData.distributed_point_per_period
|
|
971
|
+
),
|
|
972
|
+
period: Number(originBorrowIncentivePoolData.point_distribution_time),
|
|
973
|
+
maxStake: Number(originBorrowIncentivePoolData.max_stakes),
|
|
974
|
+
staked: Number(originBorrowIncentivePoolData.stakes),
|
|
975
|
+
index: Number(originBorrowIncentivePoolData.index),
|
|
976
|
+
createdAt: Number(originBorrowIncentivePoolData.created_at),
|
|
977
|
+
lastUpdate: Number(originBorrowIncentivePoolData.last_update)
|
|
978
|
+
};
|
|
979
|
+
};
|
|
980
|
+
var calculateBorrowIncentivePoolData = (parsedBorrowIncentivePoolData, borrowIncentiveCoinPrice, borrowIncentiveCoinDecimal) => {
|
|
981
|
+
const baseIndexRate = 1e9;
|
|
982
|
+
const distributedPointPerSec = (0, import_bignumber.default)(
|
|
983
|
+
parsedBorrowIncentivePoolData.pointPerPeriod
|
|
984
|
+
).dividedBy(parsedBorrowIncentivePoolData.period);
|
|
985
|
+
const pointPerSec = (0, import_bignumber.default)(
|
|
986
|
+
parsedBorrowIncentivePoolData.pointPerPeriod
|
|
987
|
+
).dividedBy(parsedBorrowIncentivePoolData.period);
|
|
988
|
+
const remainingPeriod = (0, import_bignumber.default)(parsedBorrowIncentivePoolData.maxPoint).minus(parsedBorrowIncentivePoolData.distributedPoint).dividedBy(pointPerSec);
|
|
989
|
+
const startDate = parsedBorrowIncentivePoolData.createdAt;
|
|
990
|
+
const endDate = remainingPeriod.plus(parsedBorrowIncentivePoolData.lastUpdate).integerValue().toNumber();
|
|
991
|
+
const timeDelta = (0, import_bignumber.default)(
|
|
992
|
+
Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) - parsedBorrowIncentivePoolData.lastUpdate
|
|
993
|
+
).dividedBy(parsedBorrowIncentivePoolData.period).toFixed(0);
|
|
994
|
+
const remainingPoints = (0, import_bignumber.default)(
|
|
995
|
+
parsedBorrowIncentivePoolData.maxPoint
|
|
996
|
+
).minus(parsedBorrowIncentivePoolData.distributedPoint);
|
|
997
|
+
const accumulatedPoints = import_bignumber.default.minimum(
|
|
998
|
+
(0, import_bignumber.default)(timeDelta).multipliedBy(
|
|
999
|
+
parsedBorrowIncentivePoolData.pointPerPeriod
|
|
1000
|
+
),
|
|
1001
|
+
remainingPoints
|
|
1002
|
+
);
|
|
1003
|
+
const currentPointIndex = (0, import_bignumber.default)(parsedBorrowIncentivePoolData.index).plus(
|
|
1004
|
+
accumulatedPoints.dividedBy(parsedBorrowIncentivePoolData.staked).isFinite() ? (0, import_bignumber.default)(baseIndexRate).multipliedBy(accumulatedPoints).dividedBy(parsedBorrowIncentivePoolData.staked) : 0
|
|
1005
|
+
);
|
|
1006
|
+
const currentTotalDistributedPoint = (0, import_bignumber.default)(
|
|
1007
|
+
parsedBorrowIncentivePoolData.distributedPoint
|
|
1008
|
+
).plus(accumulatedPoints);
|
|
1009
|
+
const stakedAmount = (0, import_bignumber.default)(parsedBorrowIncentivePoolData.staked);
|
|
1010
|
+
const stakedCoin = stakedAmount.shiftedBy(-1 * borrowIncentiveCoinDecimal);
|
|
1011
|
+
const stakedValue = stakedCoin.multipliedBy(borrowIncentiveCoinPrice);
|
|
1012
|
+
return {
|
|
1013
|
+
distributedPointPerSec: distributedPointPerSec.toNumber(),
|
|
1014
|
+
accumulatedPoints: accumulatedPoints.toNumber(),
|
|
1015
|
+
currentPointIndex: currentPointIndex.toNumber(),
|
|
1016
|
+
currentTotalDistributedPoint: currentTotalDistributedPoint.toNumber(),
|
|
1017
|
+
startDate: new Date(startDate * 1e3),
|
|
1018
|
+
endDate: new Date(endDate * 1e3),
|
|
1019
|
+
stakedAmount: stakedAmount.toNumber(),
|
|
1020
|
+
stakedCoin: stakedCoin.toNumber(),
|
|
1021
|
+
stakedValue: stakedValue.toNumber()
|
|
1022
|
+
};
|
|
1023
|
+
};
|
|
1024
|
+
var parseOriginBorrowIncentiveRewardPoolData = (originBorrowIncentiveRewardPoolData) => {
|
|
1025
|
+
return {
|
|
1026
|
+
rewardType: (0, import_utils.normalizeStructTag)(
|
|
1027
|
+
originBorrowIncentiveRewardPoolData.reward_type.name
|
|
1028
|
+
),
|
|
1029
|
+
claimedRewards: Number(originBorrowIncentiveRewardPoolData.claimed_rewards),
|
|
1030
|
+
exchangeRateNumerator: Number(
|
|
1031
|
+
originBorrowIncentiveRewardPoolData.exchange_rate_numerator
|
|
1032
|
+
),
|
|
1033
|
+
exchangeRateDenominator: Number(
|
|
1034
|
+
originBorrowIncentiveRewardPoolData.exchange_rate_denominator
|
|
1035
|
+
),
|
|
1036
|
+
remainingRewards: Number(
|
|
1037
|
+
originBorrowIncentiveRewardPoolData.remaining_reward
|
|
1038
|
+
)
|
|
1039
|
+
};
|
|
1040
|
+
};
|
|
1041
|
+
var calculateBorrowIncentiveRewardPoolData = (parsedBorrowIncentivePoolData, parsedBorrowIncentiveRewardPoolData, calculatedBorrowIncentivePoolData, rewardCoinPrice, rewardCoinDecimal) => {
|
|
1042
|
+
const rateYearFactor = 365 * 24 * 60 * 60;
|
|
1043
|
+
const rewardPerSec = (0, import_bignumber.default)(
|
|
1044
|
+
calculatedBorrowIncentivePoolData.distributedPointPerSec
|
|
1045
|
+
).multipliedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateNumerator).dividedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateDenominator);
|
|
1046
|
+
const totalRewardAmount = (0, import_bignumber.default)(parsedBorrowIncentivePoolData.maxPoint).multipliedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateNumerator).dividedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateDenominator);
|
|
1047
|
+
const totalRewardCoin = totalRewardAmount.shiftedBy(-1 * rewardCoinDecimal);
|
|
1048
|
+
const totalRewardValue = totalRewardCoin.multipliedBy(rewardCoinPrice);
|
|
1049
|
+
const remaindRewardAmount = (0, import_bignumber.default)(
|
|
1050
|
+
parsedBorrowIncentiveRewardPoolData.remainingRewards
|
|
1051
|
+
);
|
|
1052
|
+
const remaindRewardCoin = remaindRewardAmount.shiftedBy(
|
|
1053
|
+
-1 * rewardCoinDecimal
|
|
1054
|
+
);
|
|
1055
|
+
const remaindRewardValue = remaindRewardCoin.multipliedBy(rewardCoinPrice);
|
|
1056
|
+
const claimedRewardAmount = (0, import_bignumber.default)(
|
|
1057
|
+
parsedBorrowIncentiveRewardPoolData.claimedRewards
|
|
1058
|
+
);
|
|
1059
|
+
const claimedRewardCoin = claimedRewardAmount.shiftedBy(
|
|
1060
|
+
-1 * rewardCoinDecimal
|
|
1061
|
+
);
|
|
1062
|
+
const claimedRewardValue = claimedRewardCoin.multipliedBy(rewardCoinPrice);
|
|
1063
|
+
const rewardValueForYear = (0, import_bignumber.default)(rewardPerSec).shiftedBy(-1 * rewardCoinDecimal).multipliedBy(rateYearFactor).multipliedBy(rewardCoinPrice);
|
|
1064
|
+
const rewardRate = rewardValueForYear.dividedBy(calculatedBorrowIncentivePoolData.stakedValue).isFinite() ? rewardValueForYear.dividedBy(calculatedBorrowIncentivePoolData.stakedValue).toNumber() : Infinity;
|
|
1065
|
+
return {
|
|
1066
|
+
rewardApr: rewardRate,
|
|
1067
|
+
totalRewardAmount: totalRewardAmount.toNumber(),
|
|
1068
|
+
totalRewardCoin: totalRewardCoin.toNumber(),
|
|
1069
|
+
totalRewardValue: totalRewardValue.toNumber(),
|
|
1070
|
+
remaindRewardAmount: remaindRewardAmount.toNumber(),
|
|
1071
|
+
remaindRewardCoin: remaindRewardCoin.toNumber(),
|
|
1072
|
+
remaindRewardValue: remaindRewardValue.toNumber(),
|
|
1073
|
+
claimedRewardAmount: claimedRewardAmount.toNumber(),
|
|
1074
|
+
claimedRewardCoin: claimedRewardCoin.toNumber(),
|
|
1075
|
+
claimedRewardValue: claimedRewardValue.toNumber(),
|
|
1076
|
+
rewardPerSec: rewardPerSec.toNumber()
|
|
1077
|
+
};
|
|
1078
|
+
};
|
|
1079
|
+
var parseOriginBorrowIncentiveAccountData = (originBorrowIncentiveAccountData) => {
|
|
1080
|
+
return {
|
|
1081
|
+
poolType: (0, import_utils.normalizeStructTag)(
|
|
1082
|
+
originBorrowIncentiveAccountData.pool_type.name
|
|
1083
|
+
),
|
|
1084
|
+
amount: Number(originBorrowIncentiveAccountData.amount),
|
|
1085
|
+
index: Number(originBorrowIncentiveAccountData.index),
|
|
1086
|
+
points: Number(originBorrowIncentiveAccountData.points),
|
|
1087
|
+
totalPoints: Number(originBorrowIncentiveAccountData.total_points)
|
|
903
1088
|
};
|
|
904
1089
|
};
|
|
905
1090
|
var minBigNumber = (...args) => {
|
|
@@ -912,15 +1097,45 @@ var minBigNumber = (...args) => {
|
|
|
912
1097
|
|
|
913
1098
|
// src/utils/util.ts
|
|
914
1099
|
var isMarketCoin = (coinName) => {
|
|
915
|
-
const assetCoinName = coinName.slice(1);
|
|
916
|
-
return [
|
|
1100
|
+
const assetCoinName = coinName.slice(1).toLowerCase();
|
|
1101
|
+
return coinName.charAt(0).toLowerCase() === "s" && [
|
|
917
1102
|
.../* @__PURE__ */ new Set([
|
|
918
1103
|
...SUPPORT_POOLS,
|
|
919
1104
|
...SUPPORT_COLLATERALS,
|
|
920
|
-
...
|
|
1105
|
+
...SUPPORT_SPOOLS_REWARDS
|
|
921
1106
|
])
|
|
922
1107
|
].includes(assetCoinName);
|
|
923
1108
|
};
|
|
1109
|
+
var parseAssetSymbol = (coinName) => {
|
|
1110
|
+
switch (coinName) {
|
|
1111
|
+
case "afsui":
|
|
1112
|
+
return "afSUI";
|
|
1113
|
+
case "hasui":
|
|
1114
|
+
return "haSUI";
|
|
1115
|
+
case "vsui":
|
|
1116
|
+
return "vSUI";
|
|
1117
|
+
default:
|
|
1118
|
+
return coinName.toUpperCase();
|
|
1119
|
+
}
|
|
1120
|
+
};
|
|
1121
|
+
var parseDataFromPythPriceFeed = (feed, address) => {
|
|
1122
|
+
const assetCoinNames = [
|
|
1123
|
+
.../* @__PURE__ */ new Set([...SUPPORT_POOLS, ...SUPPORT_COLLATERALS])
|
|
1124
|
+
];
|
|
1125
|
+
const assetCoinName = assetCoinNames.find((assetCoinName2) => {
|
|
1126
|
+
return address.get(`core.coins.${assetCoinName2}.oracle.pyth.feed`) === feed.id;
|
|
1127
|
+
});
|
|
1128
|
+
if (assetCoinName) {
|
|
1129
|
+
const price = feed.price.price * 10 ** feed.price.expo;
|
|
1130
|
+
return {
|
|
1131
|
+
coinName: assetCoinName,
|
|
1132
|
+
price,
|
|
1133
|
+
publishTime: Number(feed.price.publishTime) * 10 ** 3
|
|
1134
|
+
};
|
|
1135
|
+
} else {
|
|
1136
|
+
throw new Error("Invalid feed id");
|
|
1137
|
+
}
|
|
1138
|
+
};
|
|
924
1139
|
|
|
925
1140
|
// src/queries/coreQuery.ts
|
|
926
1141
|
var queryMarket = async (query) => {
|
|
@@ -934,6 +1149,12 @@ var queryMarket = async (query) => {
|
|
|
934
1149
|
const pools = {};
|
|
935
1150
|
const collaterals = {};
|
|
936
1151
|
for (const pool of marketData.pools) {
|
|
1152
|
+
const coinType = "0x" + pool.type.name;
|
|
1153
|
+
const poolCoinName = query.utils.parseCoinNameFromType(coinType);
|
|
1154
|
+
const coinPrice = (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName] ?? 0;
|
|
1155
|
+
if (!SUPPORT_POOLS.includes(poolCoinName)) {
|
|
1156
|
+
continue;
|
|
1157
|
+
}
|
|
937
1158
|
const parsedMarketPoolData = parseOriginMarketPoolData({
|
|
938
1159
|
type: pool.type,
|
|
939
1160
|
maxBorrowRate: pool.maxBorrowRate,
|
|
@@ -958,9 +1179,6 @@ var queryMarket = async (query) => {
|
|
|
958
1179
|
query.utils,
|
|
959
1180
|
parsedMarketPoolData
|
|
960
1181
|
);
|
|
961
|
-
const coinType = "0x" + pool.type.name;
|
|
962
|
-
const poolCoinName = query.utils.parseCoinNameFromType(coinType);
|
|
963
|
-
const coinPrice = (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName] ?? 0;
|
|
964
1182
|
pools[poolCoinName] = {
|
|
965
1183
|
coinName: poolCoinName,
|
|
966
1184
|
symbol: query.utils.parseSymbol(poolCoinName),
|
|
@@ -979,6 +1197,12 @@ var queryMarket = async (query) => {
|
|
|
979
1197
|
};
|
|
980
1198
|
}
|
|
981
1199
|
for (const collateral of marketData.collaterals) {
|
|
1200
|
+
const coinType = "0x" + collateral.type.name;
|
|
1201
|
+
const collateralCoinName = query.utils.parseCoinNameFromType(coinType);
|
|
1202
|
+
const coinPrice = (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName] ?? 0;
|
|
1203
|
+
if (!SUPPORT_COLLATERALS.includes(collateralCoinName)) {
|
|
1204
|
+
continue;
|
|
1205
|
+
}
|
|
982
1206
|
const parsedMarketCollateralData = parseOriginMarketCollateralData({
|
|
983
1207
|
type: collateral.type,
|
|
984
1208
|
collateralFactor: collateral.collateralFactor,
|
|
@@ -993,9 +1217,6 @@ var queryMarket = async (query) => {
|
|
|
993
1217
|
query.utils,
|
|
994
1218
|
parsedMarketCollateralData
|
|
995
1219
|
);
|
|
996
|
-
const coinType = "0x" + collateral.type.name;
|
|
997
|
-
const collateralCoinName = query.utils.parseCoinNameFromType(coinType);
|
|
998
|
-
const coinPrice = (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName] ?? 0;
|
|
999
1220
|
collaterals[collateralCoinName] = {
|
|
1000
1221
|
coinName: collateralCoinName,
|
|
1001
1222
|
symbol: query.utils.parseSymbol(collateralCoinName),
|
|
@@ -1282,11 +1503,27 @@ var getObligations = async (query, ownerAddress) => {
|
|
|
1282
1503
|
if (keyObject.content && "fields" in keyObject.content) {
|
|
1283
1504
|
const fields = keyObject.content.fields;
|
|
1284
1505
|
const obligationId = String(fields.ownership.fields.of);
|
|
1285
|
-
|
|
1506
|
+
const locked = await getObligationLocked(query, obligationId);
|
|
1507
|
+
obligations.push({ id: obligationId, keyId, locked });
|
|
1286
1508
|
}
|
|
1287
1509
|
}
|
|
1288
1510
|
return obligations;
|
|
1289
1511
|
};
|
|
1512
|
+
var getObligationLocked = async (query, obligationId) => {
|
|
1513
|
+
const obligationObjectResponse = await query.suiKit.client().getObject({
|
|
1514
|
+
id: obligationId,
|
|
1515
|
+
options: {
|
|
1516
|
+
showContent: true
|
|
1517
|
+
}
|
|
1518
|
+
});
|
|
1519
|
+
let obligationLocked = false;
|
|
1520
|
+
if (obligationObjectResponse.data && obligationObjectResponse?.data?.content?.dataType === "moveObject" && "lock_key" in obligationObjectResponse.data.content.fields) {
|
|
1521
|
+
obligationLocked = Boolean(
|
|
1522
|
+
obligationObjectResponse.data.content.fields.lock_key
|
|
1523
|
+
);
|
|
1524
|
+
}
|
|
1525
|
+
return obligationLocked;
|
|
1526
|
+
};
|
|
1290
1527
|
var queryObligation = async (query, obligationId) => {
|
|
1291
1528
|
const packageId = query.address.get("core.packages.query.id");
|
|
1292
1529
|
const queryTarget = `${packageId}::obligation_query::obligation_data`;
|
|
@@ -1461,7 +1698,7 @@ var getMarketCoinAmount = async (query, marketCoinName, ownerAddress) => {
|
|
|
1461
1698
|
};
|
|
1462
1699
|
|
|
1463
1700
|
// src/queries/spoolQuery.ts
|
|
1464
|
-
var
|
|
1701
|
+
var import_utils3 = require("@mysten/sui.js/utils");
|
|
1465
1702
|
var getSpools = async (query, stakeMarketCoinNames) => {
|
|
1466
1703
|
stakeMarketCoinNames = stakeMarketCoinNames || [...SUPPORT_SPOOLS];
|
|
1467
1704
|
const stakeCoinNames = stakeMarketCoinNames.map(
|
|
@@ -1482,31 +1719,31 @@ var getSpools = async (query, stakeMarketCoinNames) => {
|
|
|
1482
1719
|
}
|
|
1483
1720
|
return spools;
|
|
1484
1721
|
};
|
|
1485
|
-
var getSpool = async (query,
|
|
1486
|
-
const
|
|
1487
|
-
marketPool = marketPool || await query.getMarketPool(
|
|
1488
|
-
const poolId = query.address.get(`spool.pools.${
|
|
1722
|
+
var getSpool = async (query, marketCoinName, marketPool) => {
|
|
1723
|
+
const coinName = query.utils.parseCoinName(marketCoinName);
|
|
1724
|
+
marketPool = marketPool || await query.getMarketPool(coinName);
|
|
1725
|
+
const poolId = query.address.get(`spool.pools.${marketCoinName}.id`);
|
|
1489
1726
|
const rewardPoolId = query.address.get(
|
|
1490
|
-
`spool.pools.${
|
|
1727
|
+
`spool.pools.${marketCoinName}.rewardPoolId`
|
|
1491
1728
|
);
|
|
1492
1729
|
let spool = void 0;
|
|
1493
|
-
const
|
|
1730
|
+
const spoolObjectResponse = await query.suiKit.client().multiGetObjects({
|
|
1494
1731
|
ids: [poolId, rewardPoolId],
|
|
1495
1732
|
options: {
|
|
1496
1733
|
showContent: true
|
|
1497
1734
|
}
|
|
1498
1735
|
});
|
|
1499
|
-
if (marketPool &&
|
|
1500
|
-
const
|
|
1736
|
+
if (marketPool && spoolObjectResponse[0].data && spoolObjectResponse[1].data) {
|
|
1737
|
+
const rewardCoinName = query.utils.getSpoolRewardCoinName(marketCoinName);
|
|
1501
1738
|
const coinPrices = await query.utils.getCoinPrices([
|
|
1502
|
-
|
|
1503
|
-
|
|
1739
|
+
coinName,
|
|
1740
|
+
rewardCoinName
|
|
1504
1741
|
]);
|
|
1505
|
-
const
|
|
1506
|
-
const rewardPoolObject =
|
|
1507
|
-
if (
|
|
1508
|
-
const fields =
|
|
1509
|
-
const
|
|
1742
|
+
const spoolObject = spoolObjectResponse[0].data;
|
|
1743
|
+
const rewardPoolObject = spoolObjectResponse[1].data;
|
|
1744
|
+
if (spoolObject.content && "fields" in spoolObject.content) {
|
|
1745
|
+
const fields = spoolObject.content.fields;
|
|
1746
|
+
const parsedSpoolData = parseOriginSpoolData({
|
|
1510
1747
|
stakeType: fields.stake_type,
|
|
1511
1748
|
maxDistributedPoint: fields.max_distributed_point,
|
|
1512
1749
|
distributedPoint: fields.distributed_point,
|
|
@@ -1518,43 +1755,48 @@ var getSpool = async (query, stakeMarketCoinName, marketPool) => {
|
|
|
1518
1755
|
createdAt: fields.created_at,
|
|
1519
1756
|
lastUpdate: fields.last_update
|
|
1520
1757
|
});
|
|
1521
|
-
const
|
|
1522
|
-
const
|
|
1523
|
-
const
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1758
|
+
const marketCoinPrice = (coinPrices?.[coinName] ?? 0) * marketPool.conversionRate;
|
|
1759
|
+
const marketCoinDecimal = query.utils.getCoinDecimal(marketCoinName);
|
|
1760
|
+
const calculatedSpoolData = calculateSpoolData(
|
|
1761
|
+
parsedSpoolData,
|
|
1762
|
+
marketCoinPrice,
|
|
1763
|
+
marketCoinDecimal
|
|
1527
1764
|
);
|
|
1528
1765
|
if (rewardPoolObject.content && "fields" in rewardPoolObject.content) {
|
|
1529
1766
|
const fields2 = rewardPoolObject.content.fields;
|
|
1530
|
-
const
|
|
1767
|
+
const parsedSpoolRewardPoolData = parseOriginSpoolRewardPoolData({
|
|
1531
1768
|
claimed_rewards: fields2.claimed_rewards,
|
|
1532
1769
|
exchange_rate_numerator: fields2.exchange_rate_numerator,
|
|
1533
1770
|
exchange_rate_denominator: fields2.exchange_rate_denominator,
|
|
1534
1771
|
rewards: fields2.rewards,
|
|
1535
1772
|
spool_id: fields2.spool_id
|
|
1536
1773
|
});
|
|
1537
|
-
const rewardCoinPrice = coinPrices?.[
|
|
1538
|
-
const rewardCoinDecimal = query.utils.getCoinDecimal(
|
|
1539
|
-
const calculatedRewardPoolData =
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1774
|
+
const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
|
|
1775
|
+
const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
1776
|
+
const calculatedRewardPoolData = calculateSpoolRewardPoolData(
|
|
1777
|
+
parsedSpoolData,
|
|
1778
|
+
parsedSpoolRewardPoolData,
|
|
1779
|
+
calculatedSpoolData,
|
|
1543
1780
|
rewardCoinPrice,
|
|
1544
1781
|
rewardCoinDecimal
|
|
1545
1782
|
);
|
|
1546
1783
|
spool = {
|
|
1547
|
-
marketCoinName
|
|
1548
|
-
symbol: query.utils.parseSymbol(
|
|
1549
|
-
coinType: query.utils.parseCoinType(
|
|
1550
|
-
marketCoinType: query.utils.parseMarketCoinType(
|
|
1551
|
-
rewardCoinType: isMarketCoin(
|
|
1552
|
-
coinDecimal: query.utils.getCoinDecimal(
|
|
1553
|
-
rewardCoinDecimal: query.utils.getCoinDecimal(
|
|
1554
|
-
coinPrice: coinPrices?.[
|
|
1555
|
-
marketCoinPrice
|
|
1784
|
+
marketCoinName,
|
|
1785
|
+
symbol: query.utils.parseSymbol(marketCoinName),
|
|
1786
|
+
coinType: query.utils.parseCoinType(coinName),
|
|
1787
|
+
marketCoinType: query.utils.parseMarketCoinType(coinName),
|
|
1788
|
+
rewardCoinType: isMarketCoin(rewardCoinName) ? query.utils.parseMarketCoinType(rewardCoinName) : query.utils.parseCoinType(rewardCoinName),
|
|
1789
|
+
coinDecimal: query.utils.getCoinDecimal(coinName),
|
|
1790
|
+
rewardCoinDecimal: query.utils.getCoinDecimal(rewardCoinName),
|
|
1791
|
+
coinPrice: coinPrices?.[coinName] ?? 0,
|
|
1792
|
+
marketCoinPrice,
|
|
1556
1793
|
rewardCoinPrice,
|
|
1557
|
-
|
|
1794
|
+
maxPoint: parsedSpoolData.maxPoint,
|
|
1795
|
+
distributedPoint: parsedSpoolData.distributedPoint,
|
|
1796
|
+
maxStake: parsedSpoolData.maxStake,
|
|
1797
|
+
...calculatedSpoolData,
|
|
1798
|
+
exchangeRateNumerator: parsedSpoolRewardPoolData.exchangeRateNumerator,
|
|
1799
|
+
exchangeRateDenominator: parsedSpoolRewardPoolData.exchangeRateDenominator,
|
|
1558
1800
|
...calculatedRewardPoolData
|
|
1559
1801
|
};
|
|
1560
1802
|
}
|
|
@@ -1612,7 +1854,7 @@ var getStakeAccounts = async (query, ownerAddress) => {
|
|
|
1612
1854
|
const index = Number(fields.index);
|
|
1613
1855
|
const points = Number(fields.points);
|
|
1614
1856
|
const totalPoints = Number(fields.total_points);
|
|
1615
|
-
if ((0,
|
|
1857
|
+
if ((0, import_utils3.normalizeStructTag)(type) === stakeMarketCoinTypes.ssui) {
|
|
1616
1858
|
stakeAccounts.ssui.push({
|
|
1617
1859
|
id,
|
|
1618
1860
|
type,
|
|
@@ -1623,7 +1865,7 @@ var getStakeAccounts = async (query, ownerAddress) => {
|
|
|
1623
1865
|
points,
|
|
1624
1866
|
totalPoints
|
|
1625
1867
|
});
|
|
1626
|
-
} else if ((0,
|
|
1868
|
+
} else if ((0, import_utils3.normalizeStructTag)(type) === stakeMarketCoinTypes.susdc) {
|
|
1627
1869
|
stakeAccounts.susdc.push({
|
|
1628
1870
|
id,
|
|
1629
1871
|
type,
|
|
@@ -1634,7 +1876,7 @@ var getStakeAccounts = async (query, ownerAddress) => {
|
|
|
1634
1876
|
points,
|
|
1635
1877
|
totalPoints
|
|
1636
1878
|
});
|
|
1637
|
-
} else if ((0,
|
|
1879
|
+
} else if ((0, import_utils3.normalizeStructTag)(type) === stakeMarketCoinTypes.susdt) {
|
|
1638
1880
|
stakeAccounts.susdt.push({
|
|
1639
1881
|
id,
|
|
1640
1882
|
type,
|
|
@@ -1694,30 +1936,30 @@ var getStakePool = async (query, marketCoinName) => {
|
|
|
1694
1936
|
}
|
|
1695
1937
|
return stakePool;
|
|
1696
1938
|
};
|
|
1697
|
-
var
|
|
1939
|
+
var getStakeRewardPool = async (query, marketCoinName) => {
|
|
1698
1940
|
const poolId = query.address.get(
|
|
1699
1941
|
`spool.pools.${marketCoinName}.rewardPoolId`
|
|
1700
1942
|
);
|
|
1701
|
-
let
|
|
1702
|
-
const
|
|
1943
|
+
let stakeRewardPool = void 0;
|
|
1944
|
+
const stakeRewardPoolObjectResponse = await query.suiKit.client().getObject({
|
|
1703
1945
|
id: poolId,
|
|
1704
1946
|
options: {
|
|
1705
1947
|
showContent: true,
|
|
1706
1948
|
showType: true
|
|
1707
1949
|
}
|
|
1708
1950
|
});
|
|
1709
|
-
if (
|
|
1710
|
-
const
|
|
1711
|
-
const id =
|
|
1712
|
-
const type =
|
|
1713
|
-
if (
|
|
1714
|
-
const fields =
|
|
1951
|
+
if (stakeRewardPoolObjectResponse.data) {
|
|
1952
|
+
const stakeRewardPoolObject = stakeRewardPoolObjectResponse.data;
|
|
1953
|
+
const id = stakeRewardPoolObject.objectId;
|
|
1954
|
+
const type = stakeRewardPoolObject.type;
|
|
1955
|
+
if (stakeRewardPoolObject.content && "fields" in stakeRewardPoolObject.content) {
|
|
1956
|
+
const fields = stakeRewardPoolObject.content.fields;
|
|
1715
1957
|
const stakePoolId = String(fields.spool_id);
|
|
1716
1958
|
const ratioNumerator = Number(fields.exchange_rate_numerator);
|
|
1717
1959
|
const ratioDenominator = Number(fields.exchange_rate_denominator);
|
|
1718
1960
|
const rewards = Number(fields.rewards);
|
|
1719
1961
|
const claimedRewards = Number(fields.claimed_rewards);
|
|
1720
|
-
|
|
1962
|
+
stakeRewardPool = {
|
|
1721
1963
|
id,
|
|
1722
1964
|
type,
|
|
1723
1965
|
stakePoolId,
|
|
@@ -1728,7 +1970,106 @@ var getRewardPool = async (query, marketCoinName) => {
|
|
|
1728
1970
|
};
|
|
1729
1971
|
}
|
|
1730
1972
|
}
|
|
1731
|
-
return
|
|
1973
|
+
return stakeRewardPool;
|
|
1974
|
+
};
|
|
1975
|
+
|
|
1976
|
+
// src/queries/borrowIncentiveQuery.ts
|
|
1977
|
+
var import_sui_kit2 = require("@scallop-io/sui-kit");
|
|
1978
|
+
var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames) => {
|
|
1979
|
+
borrowIncentiveCoinNames = borrowIncentiveCoinNames || [
|
|
1980
|
+
...SUPPORT_BORROW_INCENTIVE_POOLS
|
|
1981
|
+
];
|
|
1982
|
+
const queryPkgId = query.address.get("borrowIncentive.query");
|
|
1983
|
+
const incentivePoolsId = query.address.get("borrowIncentive.incentivePools");
|
|
1984
|
+
const txBlock = new import_sui_kit2.SuiTxBlock();
|
|
1985
|
+
const queryTarget = `${queryPkgId}::incentive_pools_query::incentive_pools_data`;
|
|
1986
|
+
txBlock.moveCall(queryTarget, [incentivePoolsId], ["0x2::sui::SUI"]);
|
|
1987
|
+
const queryResult = await query.suiKit.inspectTxn(txBlock);
|
|
1988
|
+
const borrowIncentivePoolsQueryData = queryResult.events[0].parsedJson;
|
|
1989
|
+
const parsedBorrowIncentiveRewardPoolData = parseOriginBorrowIncentiveRewardPoolData(
|
|
1990
|
+
borrowIncentivePoolsQueryData.reward_pool
|
|
1991
|
+
);
|
|
1992
|
+
const rewardCoinType = parsedBorrowIncentiveRewardPoolData.rewardType;
|
|
1993
|
+
const borrowIncentivePools = {};
|
|
1994
|
+
for (const pool of borrowIncentivePoolsQueryData.incentive_pools) {
|
|
1995
|
+
const coinType = "0x" + pool.pool_type.name;
|
|
1996
|
+
const coinName = query.utils.parseCoinNameFromType(coinType);
|
|
1997
|
+
const rewardCoinName = query.utils.parseCoinNameFromType(rewardCoinType);
|
|
1998
|
+
if (!borrowIncentiveCoinNames.includes(coinName)) {
|
|
1999
|
+
continue;
|
|
2000
|
+
}
|
|
2001
|
+
const coinPrices = await query.utils.getCoinPrices([
|
|
2002
|
+
coinName,
|
|
2003
|
+
rewardCoinName
|
|
2004
|
+
]);
|
|
2005
|
+
const parsedBorrowIncentivePoolData = parseOriginBorrowIncentivePoolData(pool);
|
|
2006
|
+
const coinPrice = coinPrices?.[coinName] ?? 0;
|
|
2007
|
+
const coinDecimal = query.utils.getCoinDecimal(coinName);
|
|
2008
|
+
const calculatedBorrowIncentivePoolData = calculateBorrowIncentivePoolData(
|
|
2009
|
+
parsedBorrowIncentivePoolData,
|
|
2010
|
+
coinPrice,
|
|
2011
|
+
coinDecimal
|
|
2012
|
+
);
|
|
2013
|
+
const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
|
|
2014
|
+
const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
2015
|
+
const calculatedBorrowIncentiveRewardPoolData = calculateBorrowIncentiveRewardPoolData(
|
|
2016
|
+
parsedBorrowIncentivePoolData,
|
|
2017
|
+
parsedBorrowIncentiveRewardPoolData,
|
|
2018
|
+
calculatedBorrowIncentivePoolData,
|
|
2019
|
+
rewardCoinPrice,
|
|
2020
|
+
rewardCoinDecimal
|
|
2021
|
+
);
|
|
2022
|
+
borrowIncentivePools[coinName] = {
|
|
2023
|
+
coinName,
|
|
2024
|
+
symbol: query.utils.parseSymbol(coinName),
|
|
2025
|
+
coinType,
|
|
2026
|
+
rewardCoinType,
|
|
2027
|
+
coinDecimal,
|
|
2028
|
+
rewardCoinDecimal,
|
|
2029
|
+
coinPrice,
|
|
2030
|
+
rewardCoinPrice,
|
|
2031
|
+
maxPoint: parsedBorrowIncentivePoolData.maxPoint,
|
|
2032
|
+
distributedPoint: parsedBorrowIncentivePoolData.distributedPoint,
|
|
2033
|
+
maxStake: parsedBorrowIncentivePoolData.maxStake,
|
|
2034
|
+
...calculatedBorrowIncentivePoolData,
|
|
2035
|
+
exchangeRateNumerator: parsedBorrowIncentiveRewardPoolData.exchangeRateNumerator,
|
|
2036
|
+
exchangeRateDenominator: parsedBorrowIncentiveRewardPoolData.exchangeRateDenominator,
|
|
2037
|
+
...calculatedBorrowIncentiveRewardPoolData
|
|
2038
|
+
};
|
|
2039
|
+
}
|
|
2040
|
+
return borrowIncentivePools;
|
|
2041
|
+
};
|
|
2042
|
+
var queryBorrowIncentiveAccounts = async (query, obligationId, borrowIncentiveCoinNames) => {
|
|
2043
|
+
borrowIncentiveCoinNames = borrowIncentiveCoinNames || [
|
|
2044
|
+
...SUPPORT_BORROW_INCENTIVE_POOLS
|
|
2045
|
+
];
|
|
2046
|
+
const queryPkgId = query.address.get("borrowIncentive.query");
|
|
2047
|
+
const incentiveAccountsId = query.address.get(
|
|
2048
|
+
"borrowIncentive.incentiveAccounts"
|
|
2049
|
+
);
|
|
2050
|
+
const queryTarget = `${queryPkgId}::incentive_account_query::incentive_account_data`;
|
|
2051
|
+
const txBlock = new import_sui_kit2.SuiTxBlock();
|
|
2052
|
+
txBlock.moveCall(queryTarget, [incentiveAccountsId, obligationId]);
|
|
2053
|
+
const queryResult = await query.suiKit.inspectTxn(txBlock);
|
|
2054
|
+
const borrowIncentiveAccountsQueryData = queryResult.events[0].parsedJson;
|
|
2055
|
+
const borrowIncentiveAccounts = Object.values(
|
|
2056
|
+
borrowIncentiveAccountsQueryData.incentive_states
|
|
2057
|
+
).reduce((accounts, accountData) => {
|
|
2058
|
+
const parsedBorrowIncentiveAccount = parseOriginBorrowIncentiveAccountData(accountData);
|
|
2059
|
+
const poolType = parsedBorrowIncentiveAccount.poolType;
|
|
2060
|
+
const coinName = query.utils.parseCoinNameFromType(poolType);
|
|
2061
|
+
if (borrowIncentiveCoinNames && borrowIncentiveCoinNames.includes(coinName)) {
|
|
2062
|
+
accounts[coinName] = {
|
|
2063
|
+
poolType,
|
|
2064
|
+
amount: parsedBorrowIncentiveAccount.amount,
|
|
2065
|
+
points: parsedBorrowIncentiveAccount.points,
|
|
2066
|
+
totalPoints: parsedBorrowIncentiveAccount.totalPoints,
|
|
2067
|
+
index: parsedBorrowIncentiveAccount.index
|
|
2068
|
+
};
|
|
2069
|
+
}
|
|
2070
|
+
return accounts;
|
|
2071
|
+
}, {});
|
|
2072
|
+
return borrowIncentiveAccounts;
|
|
1732
2073
|
};
|
|
1733
2074
|
|
|
1734
2075
|
// src/queries/priceQuery.ts
|
|
@@ -2144,7 +2485,7 @@ var getTotalValueLocked = async (query) => {
|
|
|
2144
2485
|
var ScallopQuery = class {
|
|
2145
2486
|
constructor(params, instance) {
|
|
2146
2487
|
this.params = params;
|
|
2147
|
-
this.suiKit = instance?.suiKit ?? new
|
|
2488
|
+
this.suiKit = instance?.suiKit ?? new import_sui_kit3.SuiKit(params);
|
|
2148
2489
|
this.address = instance?.address ?? new ScallopAddress({
|
|
2149
2490
|
id: params?.addressesId || ADDRESSES_ID,
|
|
2150
2491
|
network: params?.networkType
|
|
@@ -2360,38 +2701,60 @@ var ScallopQuery = class {
|
|
|
2360
2701
|
return await getStakePool(this, stakeMarketCoinName);
|
|
2361
2702
|
}
|
|
2362
2703
|
/**
|
|
2363
|
-
* Get reward pools data.
|
|
2704
|
+
* Get stake reward pools data.
|
|
2364
2705
|
*
|
|
2365
2706
|
* @description
|
|
2366
2707
|
* For backward compatible, it is recommended to use `getSpools` method
|
|
2367
2708
|
* to get all spools data.
|
|
2368
2709
|
*
|
|
2369
2710
|
* @param stakeMarketCoinNames - Specific an array of stake market coin name.
|
|
2370
|
-
* @return
|
|
2711
|
+
* @return Stake reward pools data.
|
|
2371
2712
|
*/
|
|
2372
|
-
async
|
|
2713
|
+
async getStakeRewardPools(stakeMarketCoinNames) {
|
|
2373
2714
|
stakeMarketCoinNames = stakeMarketCoinNames ?? [...SUPPORT_SPOOLS];
|
|
2374
|
-
const
|
|
2715
|
+
const stakeRewardPools = {};
|
|
2375
2716
|
for (const stakeMarketCoinName of stakeMarketCoinNames) {
|
|
2376
|
-
const
|
|
2377
|
-
|
|
2378
|
-
|
|
2717
|
+
const stakeRewardPool = await getStakeRewardPool(
|
|
2718
|
+
this,
|
|
2719
|
+
stakeMarketCoinName
|
|
2720
|
+
);
|
|
2721
|
+
if (stakeRewardPool) {
|
|
2722
|
+
stakeRewardPools[stakeMarketCoinName] = stakeRewardPool;
|
|
2379
2723
|
}
|
|
2380
2724
|
}
|
|
2381
|
-
return
|
|
2725
|
+
return stakeRewardPools;
|
|
2382
2726
|
}
|
|
2383
2727
|
/**
|
|
2384
|
-
* Get reward pool data.
|
|
2728
|
+
* Get stake reward pool data.
|
|
2385
2729
|
*
|
|
2386
2730
|
* @description
|
|
2387
2731
|
* For backward compatible, it is recommended to use `getSpool` method
|
|
2388
2732
|
* to get spool data.
|
|
2389
2733
|
*
|
|
2390
2734
|
* @param marketCoinName - Specific support stake market coin name.
|
|
2391
|
-
* @return
|
|
2735
|
+
* @return Stake reward pool data.
|
|
2736
|
+
*/
|
|
2737
|
+
async getStakeRewardPool(stakeMarketCoinName) {
|
|
2738
|
+
return await getStakeRewardPool(this, stakeMarketCoinName);
|
|
2739
|
+
}
|
|
2740
|
+
/**
|
|
2741
|
+
* Get borrow incentive pools data.
|
|
2742
|
+
*
|
|
2743
|
+
* @param coinNames - Specific an array of support borrow incentive coin name.
|
|
2744
|
+
* @return Borrow incentive pools data.
|
|
2745
|
+
*/
|
|
2746
|
+
async getBorrowIncentivePools(coinNames) {
|
|
2747
|
+
return await queryBorrowIncentivePools(this, coinNames);
|
|
2748
|
+
}
|
|
2749
|
+
/**
|
|
2750
|
+
* Get borrow incentive accounts data.
|
|
2751
|
+
*
|
|
2752
|
+
* @param coinNames - Specific support borrow incentive coin name.
|
|
2753
|
+
* @param ownerAddress - The owner address.
|
|
2754
|
+
* @return Borrow incentive accounts data.
|
|
2392
2755
|
*/
|
|
2393
|
-
async
|
|
2394
|
-
return await
|
|
2756
|
+
async getBorrowIncentiveAccounts(obligationId, coinNames) {
|
|
2757
|
+
return await queryBorrowIncentiveAccounts(this, obligationId, coinNames);
|
|
2395
2758
|
}
|
|
2396
2759
|
/**
|
|
2397
2760
|
* Get user lending and spool infomation for specific pools.
|
|
@@ -2455,16 +2818,25 @@ var ScallopUtils = class {
|
|
|
2455
2818
|
constructor(params, instance) {
|
|
2456
2819
|
this._priceMap = /* @__PURE__ */ new Map();
|
|
2457
2820
|
/**
|
|
2458
|
-
* Get reward type of
|
|
2821
|
+
* Get reward type of spool.
|
|
2459
2822
|
*
|
|
2460
2823
|
* @param stakeMarketCoinName - Support stake market coin.
|
|
2461
|
-
* @return
|
|
2824
|
+
* @return Spool reward coin name.
|
|
2825
|
+
*/
|
|
2826
|
+
this.getSpoolRewardCoinName = (stakeMarketCoinName) => {
|
|
2827
|
+
return spoolRewardCoins[stakeMarketCoinName];
|
|
2828
|
+
};
|
|
2829
|
+
/**
|
|
2830
|
+
* Get reward type of borrow incentive pool.
|
|
2831
|
+
*
|
|
2832
|
+
* @param borrowIncentiveCoinName - Support borrow incentive coin.
|
|
2833
|
+
* @return Borrow incentive reward coin name.
|
|
2462
2834
|
*/
|
|
2463
|
-
this.
|
|
2464
|
-
return
|
|
2835
|
+
this.getBorrowIncentiveRewardCoinName = (borrowIncentiveCoinName) => {
|
|
2836
|
+
return borrowIncentiveRewardCoins[borrowIncentiveCoinName];
|
|
2465
2837
|
};
|
|
2466
2838
|
this.params = params;
|
|
2467
|
-
this._suiKit = instance?.suiKit ?? new
|
|
2839
|
+
this._suiKit = instance?.suiKit ?? new import_sui_kit4.SuiKit(params);
|
|
2468
2840
|
this._address = instance?.address ?? new ScallopAddress({
|
|
2469
2841
|
id: params?.addressesId || ADDRESSES_ID,
|
|
2470
2842
|
network: params?.networkType
|
|
@@ -2494,9 +2866,10 @@ var ScallopUtils = class {
|
|
|
2494
2866
|
*/
|
|
2495
2867
|
parseSymbol(coinName) {
|
|
2496
2868
|
if (isMarketCoin(coinName)) {
|
|
2497
|
-
|
|
2869
|
+
const assetCoinName = coinName.slice(1).toLowerCase();
|
|
2870
|
+
return coinName.slice(0, 1).toLowerCase() + parseAssetSymbol(assetCoinName);
|
|
2498
2871
|
} else {
|
|
2499
|
-
return coinName
|
|
2872
|
+
return parseAssetSymbol(coinName);
|
|
2500
2873
|
}
|
|
2501
2874
|
}
|
|
2502
2875
|
/**
|
|
@@ -2512,13 +2885,13 @@ var ScallopUtils = class {
|
|
|
2512
2885
|
*/
|
|
2513
2886
|
parseCoinType(coinName) {
|
|
2514
2887
|
coinName = isMarketCoin(coinName) ? this.parseCoinName(coinName) : coinName;
|
|
2515
|
-
const coinPackageId = this._address.get(`core.coins.${coinName}.id`)
|
|
2888
|
+
const coinPackageId = this._address.get(`core.coins.${coinName}.id`) || coinIds[coinName] || void 0;
|
|
2516
2889
|
if (!coinPackageId) {
|
|
2517
2890
|
throw Error(`Coin ${coinName} is not supported`);
|
|
2518
2891
|
}
|
|
2519
2892
|
if (coinName === "sui")
|
|
2520
|
-
return (0,
|
|
2521
|
-
const
|
|
2893
|
+
return (0, import_utils7.normalizeStructTag)(`${coinPackageId}::sui::SUI`);
|
|
2894
|
+
const wormHolePckageIds = [
|
|
2522
2895
|
this._address.get("core.coins.usdc.id") ?? wormholeCoinIds.usdc,
|
|
2523
2896
|
this._address.get("core.coins.usdt.id") ?? wormholeCoinIds.usdt,
|
|
2524
2897
|
this._address.get("core.coins.eth.id") ?? wormholeCoinIds.eth,
|
|
@@ -2526,8 +2899,13 @@ var ScallopUtils = class {
|
|
|
2526
2899
|
this._address.get("core.coins.sol.id") ?? wormholeCoinIds.sol,
|
|
2527
2900
|
this._address.get("core.coins.apt.id") ?? wormholeCoinIds.apt
|
|
2528
2901
|
];
|
|
2529
|
-
|
|
2902
|
+
const voloPckageIds = [
|
|
2903
|
+
this._address.get("core.coins.vsui.id") ?? voloCoinIds.vsui
|
|
2904
|
+
];
|
|
2905
|
+
if (wormHolePckageIds.includes(coinPackageId)) {
|
|
2530
2906
|
return `${coinPackageId}::coin::COIN`;
|
|
2907
|
+
} else if (voloPckageIds.includes(coinPackageId)) {
|
|
2908
|
+
return `${coinPackageId}::cert::CERT`;
|
|
2531
2909
|
} else {
|
|
2532
2910
|
return `${coinPackageId}::${coinName}::${coinName.toUpperCase()}`;
|
|
2533
2911
|
}
|
|
@@ -2544,7 +2922,7 @@ var ScallopUtils = class {
|
|
|
2544
2922
|
return `${PROTOCOL_OBJECT_ID}::reserve::MarketCoin<${coinType}>`;
|
|
2545
2923
|
}
|
|
2546
2924
|
parseCoinNameFromType(coinType) {
|
|
2547
|
-
coinType = (0,
|
|
2925
|
+
coinType = (0, import_utils7.normalizeStructTag)(coinType);
|
|
2548
2926
|
const coinTypeRegex = new RegExp(`((0x[^:]+::[^:]+::[^<>]+))(?![^<>]*<)`);
|
|
2549
2927
|
const coinTypeMatch = coinType.match(coinTypeRegex);
|
|
2550
2928
|
const isMarketCoinType = coinType.includes("reserve::MarketCoin");
|
|
@@ -2557,7 +2935,10 @@ var ScallopUtils = class {
|
|
|
2557
2935
|
[`${this._address.get("core.coins.sol.id") ?? wormholeCoinIds.sol}::coin::COIN`]: "sol",
|
|
2558
2936
|
[`${this._address.get("core.coins.apt.id") ?? wormholeCoinIds.apt}::coin::COIN`]: "apt"
|
|
2559
2937
|
};
|
|
2560
|
-
const
|
|
2938
|
+
const voloCoinTypeMap = {
|
|
2939
|
+
[`${this._address.get("core.coins.vsui.id") ?? voloCoinIds.vsui}::cert::CERT`]: "vsui"
|
|
2940
|
+
};
|
|
2941
|
+
const assetCoinName = wormHoleCoinTypeMap[coinType] || voloCoinTypeMap[coinType] || coinType.split("::")[2].toLowerCase();
|
|
2561
2942
|
return isMarketCoinType ? this.parseMarketCoinName(assetCoinName) : assetCoinName;
|
|
2562
2943
|
}
|
|
2563
2944
|
/**
|
|
@@ -2605,7 +2986,7 @@ var ScallopUtils = class {
|
|
|
2605
2986
|
* @param coinType - The coin type, default is 0x2::SUI::SUI.
|
|
2606
2987
|
* @return The selected transaction coin arguments.
|
|
2607
2988
|
*/
|
|
2608
|
-
async selectCoinIds(amount, coinType =
|
|
2989
|
+
async selectCoinIds(amount, coinType = import_utils7.SUI_TYPE_ARG, ownerAddress) {
|
|
2609
2990
|
ownerAddress = ownerAddress || this._suiKit.currentAddress();
|
|
2610
2991
|
const coins = await this._suiKit.suiInteractor.selectCoins(
|
|
2611
2992
|
ownerAddress,
|
|
@@ -2680,13 +3061,14 @@ var ScallopUtils = class {
|
|
|
2680
3061
|
);
|
|
2681
3062
|
try {
|
|
2682
3063
|
const priceFeeds = await pythConnection.getLatestPriceFeeds(priceIds) || [];
|
|
2683
|
-
for (const feed of priceFeeds) {
|
|
3064
|
+
for (const [index, feed] of priceFeeds.entries()) {
|
|
2684
3065
|
const data = parseDataFromPythPriceFeed(feed, this._address);
|
|
2685
|
-
|
|
3066
|
+
const coinName = lackPricesCoinNames[index];
|
|
3067
|
+
this._priceMap.set(coinName, {
|
|
2686
3068
|
price: data.price,
|
|
2687
3069
|
publishTime: data.publishTime
|
|
2688
3070
|
});
|
|
2689
|
-
coinPrices[
|
|
3071
|
+
coinPrices[coinName] = data.price;
|
|
2690
3072
|
}
|
|
2691
3073
|
} catch (_e) {
|
|
2692
3074
|
for (const coinName of lackPricesCoinNames) {
|
|
@@ -2724,16 +3106,16 @@ var ScallopUtils = class {
|
|
|
2724
3106
|
};
|
|
2725
3107
|
|
|
2726
3108
|
// src/models/scallopBuilder.ts
|
|
2727
|
-
var
|
|
2728
|
-
var
|
|
3109
|
+
var import_utils16 = require("@mysten/sui.js/utils");
|
|
3110
|
+
var import_sui_kit8 = require("@scallop-io/sui-kit");
|
|
2729
3111
|
|
|
2730
3112
|
// src/builders/coreBuilder.ts
|
|
2731
3113
|
var import_transactions = require("@mysten/sui.js/transactions");
|
|
2732
|
-
var
|
|
2733
|
-
var
|
|
3114
|
+
var import_utils10 = require("@mysten/sui.js/utils");
|
|
3115
|
+
var import_sui_kit5 = require("@scallop-io/sui-kit");
|
|
2734
3116
|
|
|
2735
3117
|
// src/builders/oracle.ts
|
|
2736
|
-
var
|
|
3118
|
+
var import_utils9 = require("@mysten/sui.js/utils");
|
|
2737
3119
|
var import_pyth_sui_js2 = require("@pythnetwork/pyth-sui-js");
|
|
2738
3120
|
var updateOracles = async (builder, txBlock, assetCoinNames) => {
|
|
2739
3121
|
assetCoinNames = assetCoinNames ?? [
|
|
@@ -2839,39 +3221,32 @@ var priceUpdateRequest = (txBlock, packageId, xOracleId, coinType) => {
|
|
|
2839
3221
|
var confirmPriceUpdateRequest = (txBlock, packageId, xOracleId, request, coinType) => {
|
|
2840
3222
|
const target = `${packageId}::x_oracle::confirm_price_update_request`;
|
|
2841
3223
|
const typeArgs = [coinType];
|
|
2842
|
-
txBlock.moveCall(target, [xOracleId, request,
|
|
3224
|
+
txBlock.moveCall(target, [xOracleId, request, import_utils9.SUI_CLOCK_OBJECT_ID], typeArgs);
|
|
2843
3225
|
return txBlock;
|
|
2844
3226
|
};
|
|
2845
3227
|
var updateSupraPrice = (txBlock, packageId, request, holderId, registryId, coinType) => {
|
|
2846
3228
|
txBlock.moveCall(
|
|
2847
3229
|
`${packageId}::rule::set_price`,
|
|
2848
|
-
[request, holderId, registryId,
|
|
3230
|
+
[request, holderId, registryId, import_utils9.SUI_CLOCK_OBJECT_ID],
|
|
2849
3231
|
[coinType]
|
|
2850
3232
|
);
|
|
2851
3233
|
};
|
|
2852
3234
|
var updateSwitchboardPrice = (txBlock, packageId, request, aggregatorId, registryId, coinType) => {
|
|
2853
3235
|
txBlock.moveCall(
|
|
2854
3236
|
`${packageId}::rule::set_price`,
|
|
2855
|
-
[request, aggregatorId, registryId,
|
|
3237
|
+
[request, aggregatorId, registryId, import_utils9.SUI_CLOCK_OBJECT_ID],
|
|
2856
3238
|
[coinType]
|
|
2857
3239
|
);
|
|
2858
3240
|
};
|
|
2859
3241
|
var updatePythPrice = (txBlock, packageId, request, stateId, feedObjectId, registryId, coinType) => {
|
|
2860
3242
|
txBlock.moveCall(
|
|
2861
3243
|
`${packageId}::rule::set_price`,
|
|
2862
|
-
[request, stateId, feedObjectId, registryId,
|
|
3244
|
+
[request, stateId, feedObjectId, registryId, import_utils9.SUI_CLOCK_OBJECT_ID],
|
|
2863
3245
|
[coinType]
|
|
2864
3246
|
);
|
|
2865
3247
|
};
|
|
2866
3248
|
|
|
2867
3249
|
// src/builders/coreBuilder.ts
|
|
2868
|
-
var requireSender = (txBlock) => {
|
|
2869
|
-
const sender = txBlock.blockData.sender;
|
|
2870
|
-
if (!sender) {
|
|
2871
|
-
throw new Error("Sender is required");
|
|
2872
|
-
}
|
|
2873
|
-
return sender;
|
|
2874
|
-
};
|
|
2875
3250
|
var requireObligationInfo = async (...params) => {
|
|
2876
3251
|
const [builder, txBlock, obligationId, obligationKey] = params;
|
|
2877
3252
|
if (params.length === 3 && obligationId)
|
|
@@ -2932,7 +3307,7 @@ var generateCoreNormalMethod = ({
|
|
|
2932
3307
|
coreIds.coinDecimalsRegistry,
|
|
2933
3308
|
amount,
|
|
2934
3309
|
coreIds.xOracle,
|
|
2935
|
-
|
|
3310
|
+
import_utils10.SUI_CLOCK_OBJECT_ID
|
|
2936
3311
|
],
|
|
2937
3312
|
[coinType]
|
|
2938
3313
|
);
|
|
@@ -2941,7 +3316,7 @@ var generateCoreNormalMethod = ({
|
|
|
2941
3316
|
const coinType = builder.utils.parseCoinType(poolCoinName);
|
|
2942
3317
|
return txBlock.moveCall(
|
|
2943
3318
|
`${coreIds.protocolPkg}::mint::mint`,
|
|
2944
|
-
[coreIds.version, coreIds.market, coin,
|
|
3319
|
+
[coreIds.version, coreIds.market, coin, import_utils10.SUI_CLOCK_OBJECT_ID],
|
|
2945
3320
|
[coinType]
|
|
2946
3321
|
);
|
|
2947
3322
|
},
|
|
@@ -2949,7 +3324,7 @@ var generateCoreNormalMethod = ({
|
|
|
2949
3324
|
const coinType = builder.utils.parseCoinType(poolCoinName);
|
|
2950
3325
|
return txBlock.moveCall(
|
|
2951
3326
|
`${coreIds.protocolPkg}::mint::mint_entry`,
|
|
2952
|
-
[coreIds.version, coreIds.market, coin,
|
|
3327
|
+
[coreIds.version, coreIds.market, coin, import_utils10.SUI_CLOCK_OBJECT_ID],
|
|
2953
3328
|
[coinType]
|
|
2954
3329
|
);
|
|
2955
3330
|
},
|
|
@@ -2957,7 +3332,7 @@ var generateCoreNormalMethod = ({
|
|
|
2957
3332
|
const coinType = builder.utils.parseCoinType(poolCoinName);
|
|
2958
3333
|
return txBlock.moveCall(
|
|
2959
3334
|
`${coreIds.protocolPkg}::redeem::redeem`,
|
|
2960
|
-
[coreIds.version, coreIds.market, marketCoin,
|
|
3335
|
+
[coreIds.version, coreIds.market, marketCoin, import_utils10.SUI_CLOCK_OBJECT_ID],
|
|
2961
3336
|
[coinType]
|
|
2962
3337
|
);
|
|
2963
3338
|
},
|
|
@@ -2965,7 +3340,7 @@ var generateCoreNormalMethod = ({
|
|
|
2965
3340
|
const coinType = builder.utils.parseCoinType(poolCoinName);
|
|
2966
3341
|
return txBlock.moveCall(
|
|
2967
3342
|
`${coreIds.protocolPkg}::redeem::redeem_entry`,
|
|
2968
|
-
[coreIds.version, coreIds.market, marketCoin,
|
|
3343
|
+
[coreIds.version, coreIds.market, marketCoin, import_utils10.SUI_CLOCK_OBJECT_ID],
|
|
2969
3344
|
[coinType]
|
|
2970
3345
|
);
|
|
2971
3346
|
},
|
|
@@ -2981,7 +3356,7 @@ var generateCoreNormalMethod = ({
|
|
|
2981
3356
|
coreIds.coinDecimalsRegistry,
|
|
2982
3357
|
amount,
|
|
2983
3358
|
coreIds.xOracle,
|
|
2984
|
-
|
|
3359
|
+
import_utils10.SUI_CLOCK_OBJECT_ID
|
|
2985
3360
|
],
|
|
2986
3361
|
[coinType]
|
|
2987
3362
|
);
|
|
@@ -2998,7 +3373,7 @@ var generateCoreNormalMethod = ({
|
|
|
2998
3373
|
coreIds.coinDecimalsRegistry,
|
|
2999
3374
|
amount,
|
|
3000
3375
|
coreIds.xOracle,
|
|
3001
|
-
|
|
3376
|
+
import_utils10.SUI_CLOCK_OBJECT_ID
|
|
3002
3377
|
],
|
|
3003
3378
|
[coinType]
|
|
3004
3379
|
);
|
|
@@ -3012,7 +3387,7 @@ var generateCoreNormalMethod = ({
|
|
|
3012
3387
|
obligation,
|
|
3013
3388
|
coreIds.market,
|
|
3014
3389
|
coin,
|
|
3015
|
-
|
|
3390
|
+
import_utils10.SUI_CLOCK_OBJECT_ID
|
|
3016
3391
|
],
|
|
3017
3392
|
[coinType]
|
|
3018
3393
|
);
|
|
@@ -3161,7 +3536,7 @@ var generateCoreQuickMethod = ({
|
|
|
3161
3536
|
};
|
|
3162
3537
|
};
|
|
3163
3538
|
var newCoreTxBlock = (builder, initTxBlock) => {
|
|
3164
|
-
const txBlock = initTxBlock instanceof import_transactions.TransactionBlock ? new
|
|
3539
|
+
const txBlock = initTxBlock instanceof import_transactions.TransactionBlock ? new import_sui_kit5.SuiTxBlock(initTxBlock) : initTxBlock ? initTxBlock : new import_sui_kit5.SuiTxBlock();
|
|
3165
3540
|
const normalMethod = generateCoreNormalMethod({
|
|
3166
3541
|
builder,
|
|
3167
3542
|
txBlock
|
|
@@ -3190,20 +3565,13 @@ var newCoreTxBlock = (builder, initTxBlock) => {
|
|
|
3190
3565
|
|
|
3191
3566
|
// src/builders/spoolBuilder.ts
|
|
3192
3567
|
var import_transactions2 = require("@mysten/sui.js/transactions");
|
|
3193
|
-
var
|
|
3194
|
-
var
|
|
3195
|
-
var requireSender2 = (txBlock) => {
|
|
3196
|
-
const sender = txBlock.blockData.sender;
|
|
3197
|
-
if (!sender) {
|
|
3198
|
-
throw new Error("Sender is required");
|
|
3199
|
-
}
|
|
3200
|
-
return sender;
|
|
3201
|
-
};
|
|
3568
|
+
var import_utils12 = require("@mysten/sui.js/utils");
|
|
3569
|
+
var import_sui_kit6 = require("@scallop-io/sui-kit");
|
|
3202
3570
|
var requireStakeAccountIds = async (...params) => {
|
|
3203
3571
|
const [builder, txBlock, stakeMarketCoinName, stakeAccountId] = params;
|
|
3204
3572
|
if (params.length === 4 && stakeAccountId)
|
|
3205
3573
|
return [stakeAccountId];
|
|
3206
|
-
const sender =
|
|
3574
|
+
const sender = requireSender(txBlock);
|
|
3207
3575
|
const stakeAccounts = await getStakeAccounts(builder.query, sender);
|
|
3208
3576
|
if (stakeAccounts[stakeMarketCoinName].length === 0) {
|
|
3209
3577
|
throw new Error(`No stake account id found for sender ${sender}`);
|
|
@@ -3212,7 +3580,7 @@ var requireStakeAccountIds = async (...params) => {
|
|
|
3212
3580
|
};
|
|
3213
3581
|
var requireStakeAccounts = async (...params) => {
|
|
3214
3582
|
const [builder, txBlock, stakeMarketCoinName, stakeAccountId] = params;
|
|
3215
|
-
const sender =
|
|
3583
|
+
const sender = requireSender(txBlock);
|
|
3216
3584
|
const stakeAccounts = await getStakeAccounts(builder.query, sender);
|
|
3217
3585
|
if (stakeAccounts[stakeMarketCoinName].length === 0) {
|
|
3218
3586
|
throw new Error(`No stake account found for sender ${sender}`);
|
|
@@ -3237,7 +3605,7 @@ var generateSpoolNormalMethod = ({
|
|
|
3237
3605
|
);
|
|
3238
3606
|
return txBlock.moveCall(
|
|
3239
3607
|
`${spoolIds.spoolPkg}::user::new_spool_account`,
|
|
3240
|
-
[stakePoolId,
|
|
3608
|
+
[stakePoolId, import_utils12.SUI_CLOCK_OBJECT_ID],
|
|
3241
3609
|
[marketCoinType]
|
|
3242
3610
|
);
|
|
3243
3611
|
},
|
|
@@ -3248,7 +3616,7 @@ var generateSpoolNormalMethod = ({
|
|
|
3248
3616
|
);
|
|
3249
3617
|
txBlock.moveCall(
|
|
3250
3618
|
`${spoolIds.spoolPkg}::user::stake`,
|
|
3251
|
-
[stakePoolId, stakeAccount, coin,
|
|
3619
|
+
[stakePoolId, stakeAccount, coin, import_utils12.SUI_CLOCK_OBJECT_ID],
|
|
3252
3620
|
[marketCoinType]
|
|
3253
3621
|
);
|
|
3254
3622
|
},
|
|
@@ -3259,7 +3627,7 @@ var generateSpoolNormalMethod = ({
|
|
|
3259
3627
|
);
|
|
3260
3628
|
return txBlock.moveCall(
|
|
3261
3629
|
`${spoolIds.spoolPkg}::user::unstake`,
|
|
3262
|
-
[stakePoolId, stakeAccount, amount,
|
|
3630
|
+
[stakePoolId, stakeAccount, amount, import_utils12.SUI_CLOCK_OBJECT_ID],
|
|
3263
3631
|
[marketCoinType]
|
|
3264
3632
|
);
|
|
3265
3633
|
},
|
|
@@ -3271,11 +3639,11 @@ var generateSpoolNormalMethod = ({
|
|
|
3271
3639
|
`spool.pools.${stakeMarketCoinName}.rewardPoolId`
|
|
3272
3640
|
);
|
|
3273
3641
|
const marketCoinType = builder.utils.parseMarketCoinType(stakeMarketCoinName);
|
|
3274
|
-
const rewardCoinName =
|
|
3642
|
+
const rewardCoinName = spoolRewardCoins[stakeMarketCoinName];
|
|
3275
3643
|
const rewardCoinType = builder.utils.parseCoinType(rewardCoinName);
|
|
3276
3644
|
return txBlock.moveCall(
|
|
3277
3645
|
`${spoolIds.spoolPkg}::user::redeem_rewards`,
|
|
3278
|
-
[stakePoolId, rewardPoolId, stakeAccount,
|
|
3646
|
+
[stakePoolId, rewardPoolId, stakeAccount, import_utils12.SUI_CLOCK_OBJECT_ID],
|
|
3279
3647
|
[marketCoinType, rewardCoinType]
|
|
3280
3648
|
);
|
|
3281
3649
|
}
|
|
@@ -3287,7 +3655,7 @@ var generateSpoolQuickMethod = ({
|
|
|
3287
3655
|
}) => {
|
|
3288
3656
|
return {
|
|
3289
3657
|
stakeQuick: async (amountOrMarketCoin, stakeMarketCoinName, stakeAccountId) => {
|
|
3290
|
-
const sender =
|
|
3658
|
+
const sender = requireSender(txBlock);
|
|
3291
3659
|
const stakeAccountIds = await requireStakeAccountIds(
|
|
3292
3660
|
builder,
|
|
3293
3661
|
txBlock,
|
|
@@ -3346,17 +3714,17 @@ var generateSpoolQuickMethod = ({
|
|
|
3346
3714
|
stakeMarketCoinName,
|
|
3347
3715
|
stakeAccountId
|
|
3348
3716
|
);
|
|
3349
|
-
const
|
|
3717
|
+
const rewardCoins = [];
|
|
3350
3718
|
for (const accountId of stakeAccountIds) {
|
|
3351
3719
|
const rewardCoin = txBlock.claim(accountId, stakeMarketCoinName);
|
|
3352
|
-
|
|
3720
|
+
rewardCoins.push(rewardCoin);
|
|
3353
3721
|
}
|
|
3354
|
-
return
|
|
3722
|
+
return rewardCoins;
|
|
3355
3723
|
}
|
|
3356
3724
|
};
|
|
3357
3725
|
};
|
|
3358
3726
|
var newSpoolTxBlock = (builder, initTxBlock) => {
|
|
3359
|
-
const txBlock = initTxBlock instanceof import_transactions2.TransactionBlock ? new
|
|
3727
|
+
const txBlock = initTxBlock instanceof import_transactions2.TransactionBlock ? new import_sui_kit6.SuiTxBlock(initTxBlock) : initTxBlock ? initTxBlock : new import_sui_kit6.SuiTxBlock();
|
|
3360
3728
|
const normalMethod = generateSpoolNormalMethod({
|
|
3361
3729
|
builder,
|
|
3362
3730
|
txBlock
|
|
@@ -3383,13 +3751,183 @@ var newSpoolTxBlock = (builder, initTxBlock) => {
|
|
|
3383
3751
|
});
|
|
3384
3752
|
};
|
|
3385
3753
|
|
|
3754
|
+
// src/builders/borrowIncentiveBuilder.ts
|
|
3755
|
+
var import_transactions3 = require("@mysten/sui.js/transactions");
|
|
3756
|
+
var import_utils14 = require("@mysten/sui.js/utils");
|
|
3757
|
+
var import_sui_kit7 = require("@scallop-io/sui-kit");
|
|
3758
|
+
var requireObligationInfo2 = async (...params) => {
|
|
3759
|
+
const [builder, txBlock, obligationId, obligationKey] = params;
|
|
3760
|
+
if (params.length === 4 && obligationId && obligationKey && typeof obligationId === "string") {
|
|
3761
|
+
const obligationLocked = await getObligationLocked(
|
|
3762
|
+
builder.query,
|
|
3763
|
+
obligationId
|
|
3764
|
+
);
|
|
3765
|
+
return { obligationId, obligationKey, obligationLocked };
|
|
3766
|
+
}
|
|
3767
|
+
const sender = requireSender(txBlock);
|
|
3768
|
+
const obligations = await getObligations(builder.query, sender);
|
|
3769
|
+
if (obligations.length === 0) {
|
|
3770
|
+
throw new Error(`No obligation found for sender ${sender}`);
|
|
3771
|
+
}
|
|
3772
|
+
return {
|
|
3773
|
+
obligationId: obligations[0].id,
|
|
3774
|
+
obligationKey: obligations[0].keyId,
|
|
3775
|
+
obligationLocked: obligations[0].locked
|
|
3776
|
+
};
|
|
3777
|
+
};
|
|
3778
|
+
var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
|
|
3779
|
+
const borrowIncentiveIds = {
|
|
3780
|
+
borrowIncentivePkg: builder.address.get("borrowIncentive.id"),
|
|
3781
|
+
query: builder.address.get("borrowIncentive.query"),
|
|
3782
|
+
incentivePools: builder.address.get("borrowIncentive.incentivePools"),
|
|
3783
|
+
incentiveAccounts: builder.address.get(
|
|
3784
|
+
"borrowIncentive.incentiveAccounts"
|
|
3785
|
+
),
|
|
3786
|
+
obligationAccessStore: builder.address.get("core.obligationAccessStore")
|
|
3787
|
+
};
|
|
3788
|
+
return {
|
|
3789
|
+
stakeObligation: (obligationId, obligaionKey, coinName) => {
|
|
3790
|
+
const rewardCoinName = borrowIncentiveRewardCoins[coinName];
|
|
3791
|
+
const rewardType = builder.utils.parseCoinType(rewardCoinName);
|
|
3792
|
+
txBlock.moveCall(
|
|
3793
|
+
`${borrowIncentiveIds.borrowIncentivePkg}::user::stake`,
|
|
3794
|
+
[
|
|
3795
|
+
borrowIncentiveIds.incentivePools,
|
|
3796
|
+
borrowIncentiveIds.incentiveAccounts,
|
|
3797
|
+
obligaionKey,
|
|
3798
|
+
obligationId,
|
|
3799
|
+
borrowIncentiveIds.obligationAccessStore,
|
|
3800
|
+
import_utils14.SUI_CLOCK_OBJECT_ID
|
|
3801
|
+
],
|
|
3802
|
+
[rewardType]
|
|
3803
|
+
);
|
|
3804
|
+
},
|
|
3805
|
+
unstakeObligation: (obligationId, obligaionKey, coinName) => {
|
|
3806
|
+
const rewardCoinName = borrowIncentiveRewardCoins[coinName];
|
|
3807
|
+
const rewardType = builder.utils.parseCoinType(rewardCoinName);
|
|
3808
|
+
txBlock.moveCall(
|
|
3809
|
+
`${borrowIncentiveIds.borrowIncentivePkg}::user::unstake`,
|
|
3810
|
+
[
|
|
3811
|
+
borrowIncentiveIds.incentivePools,
|
|
3812
|
+
borrowIncentiveIds.incentiveAccounts,
|
|
3813
|
+
obligaionKey,
|
|
3814
|
+
obligationId,
|
|
3815
|
+
import_utils14.SUI_CLOCK_OBJECT_ID
|
|
3816
|
+
],
|
|
3817
|
+
[rewardType]
|
|
3818
|
+
);
|
|
3819
|
+
},
|
|
3820
|
+
claimBorrowIncentive: (obligationId, obligaionKey, coinName) => {
|
|
3821
|
+
const rewardCoinName = borrowIncentiveRewardCoins[coinName];
|
|
3822
|
+
const rewardType = builder.utils.parseCoinType(rewardCoinName);
|
|
3823
|
+
return txBlock.moveCall(
|
|
3824
|
+
`${borrowIncentiveIds.borrowIncentivePkg}::user::redeem_rewards`,
|
|
3825
|
+
[
|
|
3826
|
+
borrowIncentiveIds.incentivePools,
|
|
3827
|
+
borrowIncentiveIds.incentiveAccounts,
|
|
3828
|
+
obligaionKey,
|
|
3829
|
+
obligationId,
|
|
3830
|
+
import_utils14.SUI_CLOCK_OBJECT_ID
|
|
3831
|
+
],
|
|
3832
|
+
[rewardType]
|
|
3833
|
+
);
|
|
3834
|
+
}
|
|
3835
|
+
};
|
|
3836
|
+
};
|
|
3837
|
+
var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
|
|
3838
|
+
return {
|
|
3839
|
+
stakeObligationQuick: async (coinName, obligation, obligationKey) => {
|
|
3840
|
+
const {
|
|
3841
|
+
obligationId: obligationArg,
|
|
3842
|
+
obligationKey: obligationtKeyArg,
|
|
3843
|
+
obligationLocked
|
|
3844
|
+
} = await requireObligationInfo2(
|
|
3845
|
+
builder,
|
|
3846
|
+
txBlock,
|
|
3847
|
+
obligation,
|
|
3848
|
+
obligationKey
|
|
3849
|
+
);
|
|
3850
|
+
const unstakeObligationBeforeStake = !!txBlock.txBlock.blockData.transactions.find(
|
|
3851
|
+
(txn) => txn.kind === "MoveCall" && txn.target === `${builder.address.get("borrowIncentive.id")}::user::unstake`
|
|
3852
|
+
);
|
|
3853
|
+
if (!obligationLocked || unstakeObligationBeforeStake) {
|
|
3854
|
+
txBlock.stakeObligation(obligationArg, obligationtKeyArg, coinName);
|
|
3855
|
+
}
|
|
3856
|
+
},
|
|
3857
|
+
unstakeObligationQuick: async (coinName, obligation, obligationKey) => {
|
|
3858
|
+
const {
|
|
3859
|
+
obligationId: obligationArg,
|
|
3860
|
+
obligationKey: obligationtKeyArg,
|
|
3861
|
+
obligationLocked
|
|
3862
|
+
} = await requireObligationInfo2(
|
|
3863
|
+
builder,
|
|
3864
|
+
txBlock,
|
|
3865
|
+
obligation,
|
|
3866
|
+
obligationKey
|
|
3867
|
+
);
|
|
3868
|
+
if (obligationLocked) {
|
|
3869
|
+
txBlock.unstakeObligation(obligationArg, obligationtKeyArg, coinName);
|
|
3870
|
+
}
|
|
3871
|
+
},
|
|
3872
|
+
claimBorrowIncentiveQuick: async (coinName, obligation, obligationKey) => {
|
|
3873
|
+
const {
|
|
3874
|
+
obligationId: obligationArg,
|
|
3875
|
+
obligationKey: obligationtKeyArg
|
|
3876
|
+
} = await requireObligationInfo2(
|
|
3877
|
+
builder,
|
|
3878
|
+
txBlock,
|
|
3879
|
+
obligation,
|
|
3880
|
+
obligationKey
|
|
3881
|
+
);
|
|
3882
|
+
return txBlock.claimBorrowIncentive(
|
|
3883
|
+
obligationArg,
|
|
3884
|
+
obligationtKeyArg,
|
|
3885
|
+
coinName
|
|
3886
|
+
);
|
|
3887
|
+
}
|
|
3888
|
+
};
|
|
3889
|
+
};
|
|
3890
|
+
var newBorrowIncentiveTxBlock = (builder, initTxBlock) => {
|
|
3891
|
+
const txBlock = initTxBlock instanceof import_transactions3.TransactionBlock ? new import_sui_kit7.SuiTxBlock(initTxBlock) : initTxBlock ? initTxBlock : new import_sui_kit7.SuiTxBlock();
|
|
3892
|
+
const normalMethod = generateBorrowIncentiveNormalMethod({
|
|
3893
|
+
builder,
|
|
3894
|
+
txBlock
|
|
3895
|
+
});
|
|
3896
|
+
const normalTxBlock = new Proxy(txBlock, {
|
|
3897
|
+
get: (target, prop) => {
|
|
3898
|
+
if (prop in normalMethod) {
|
|
3899
|
+
return Reflect.get(normalMethod, prop);
|
|
3900
|
+
}
|
|
3901
|
+
return Reflect.get(target, prop);
|
|
3902
|
+
}
|
|
3903
|
+
});
|
|
3904
|
+
const quickMethod = generateBorrowIncentiveQuickMethod({
|
|
3905
|
+
builder,
|
|
3906
|
+
txBlock: normalTxBlock
|
|
3907
|
+
});
|
|
3908
|
+
return new Proxy(normalTxBlock, {
|
|
3909
|
+
get: (target, prop) => {
|
|
3910
|
+
if (prop in quickMethod) {
|
|
3911
|
+
return Reflect.get(quickMethod, prop);
|
|
3912
|
+
}
|
|
3913
|
+
return Reflect.get(target, prop);
|
|
3914
|
+
}
|
|
3915
|
+
});
|
|
3916
|
+
};
|
|
3917
|
+
|
|
3386
3918
|
// src/builders/index.ts
|
|
3387
3919
|
var newScallopTxBlock = (builder, initTxBlock) => {
|
|
3388
|
-
const
|
|
3920
|
+
const borrowIncentiveTxBlock = newBorrowIncentiveTxBlock(
|
|
3921
|
+
builder,
|
|
3922
|
+
initTxBlock
|
|
3923
|
+
);
|
|
3924
|
+
const spoolTxBlock = newSpoolTxBlock(builder, borrowIncentiveTxBlock);
|
|
3389
3925
|
const coreTxBlock = newCoreTxBlock(builder, spoolTxBlock);
|
|
3390
3926
|
return new Proxy(coreTxBlock, {
|
|
3391
3927
|
get: (target, prop) => {
|
|
3392
|
-
if (prop in
|
|
3928
|
+
if (prop in borrowIncentiveTxBlock) {
|
|
3929
|
+
return Reflect.get(borrowIncentiveTxBlock, prop);
|
|
3930
|
+
} else if (prop in spoolTxBlock) {
|
|
3393
3931
|
return Reflect.get(spoolTxBlock, prop);
|
|
3394
3932
|
}
|
|
3395
3933
|
return Reflect.get(target, prop);
|
|
@@ -3401,7 +3939,7 @@ var newScallopTxBlock = (builder, initTxBlock) => {
|
|
|
3401
3939
|
var ScallopBuilder = class {
|
|
3402
3940
|
constructor(params, instance) {
|
|
3403
3941
|
this.params = params;
|
|
3404
|
-
this.suiKit = instance?.suiKit ?? new
|
|
3942
|
+
this.suiKit = instance?.suiKit ?? new import_sui_kit8.SuiKit(params);
|
|
3405
3943
|
this.address = instance?.address ?? new ScallopAddress({
|
|
3406
3944
|
id: params?.addressesId || ADDRESSES_ID,
|
|
3407
3945
|
network: params?.networkType
|
|
@@ -3415,7 +3953,7 @@ var ScallopBuilder = class {
|
|
|
3415
3953
|
address: this.address,
|
|
3416
3954
|
query: this.query
|
|
3417
3955
|
});
|
|
3418
|
-
this.walletAddress = (0,
|
|
3956
|
+
this.walletAddress = (0, import_utils16.normalizeSuiAddress)(
|
|
3419
3957
|
params?.walletAddress || this.suiKit.currentAddress()
|
|
3420
3958
|
);
|
|
3421
3959
|
this.isTestnet = params.networkType ? params.networkType === "testnet" : false;
|
|
@@ -3491,7 +4029,7 @@ var ScallopBuilder = class {
|
|
|
3491
4029
|
var ScallopClient = class {
|
|
3492
4030
|
constructor(params, instance) {
|
|
3493
4031
|
this.params = params;
|
|
3494
|
-
this.suiKit = instance?.suiKit ?? new
|
|
4032
|
+
this.suiKit = instance?.suiKit ?? new import_sui_kit9.SuiKit(params);
|
|
3495
4033
|
this.address = instance?.address ?? new ScallopAddress({
|
|
3496
4034
|
id: params?.addressesId || ADDRESSES_ID,
|
|
3497
4035
|
network: params?.networkType
|
|
@@ -3511,7 +4049,7 @@ var ScallopClient = class {
|
|
|
3511
4049
|
query: this.query,
|
|
3512
4050
|
utils: this.utils
|
|
3513
4051
|
});
|
|
3514
|
-
this.walletAddress = (0,
|
|
4052
|
+
this.walletAddress = (0, import_utils17.normalizeSuiAddress)(
|
|
3515
4053
|
params?.walletAddress || this.suiKit.currentAddress()
|
|
3516
4054
|
);
|
|
3517
4055
|
}
|
|
@@ -3613,8 +4151,8 @@ var ScallopClient = class {
|
|
|
3613
4151
|
* @param stakeMarketCoinName - Support stake market coin.
|
|
3614
4152
|
* @return Reward pool data.
|
|
3615
4153
|
*/
|
|
3616
|
-
async
|
|
3617
|
-
return await this.query.
|
|
4154
|
+
async getStakeRewardPool(stakeMarketCoinName) {
|
|
4155
|
+
return await this.query.getStakeRewardPool(stakeMarketCoinName);
|
|
3618
4156
|
}
|
|
3619
4157
|
async openObligation(sign = true) {
|
|
3620
4158
|
const txBlock = this.builder.createTxBlock();
|
|
@@ -3886,11 +4424,84 @@ var ScallopClient = class {
|
|
|
3886
4424
|
const txBlock = this.builder.createTxBlock();
|
|
3887
4425
|
const sender = walletAddress || this.walletAddress;
|
|
3888
4426
|
txBlock.setSender(sender);
|
|
3889
|
-
const
|
|
4427
|
+
const rewardCoins = await txBlock.claimQuick(
|
|
3890
4428
|
stakeMarketCoinName,
|
|
3891
4429
|
stakeAccountId
|
|
3892
4430
|
);
|
|
3893
|
-
txBlock.transferObjects(
|
|
4431
|
+
txBlock.transferObjects(rewardCoins, sender);
|
|
4432
|
+
if (sign) {
|
|
4433
|
+
return await this.suiKit.signAndSendTxn(
|
|
4434
|
+
txBlock
|
|
4435
|
+
);
|
|
4436
|
+
} else {
|
|
4437
|
+
return txBlock.txBlock;
|
|
4438
|
+
}
|
|
4439
|
+
}
|
|
4440
|
+
/* ==================== Borrow Incentive Method ==================== */
|
|
4441
|
+
/**
|
|
4442
|
+
* stake obligaion.
|
|
4443
|
+
*
|
|
4444
|
+
* @param sign - Decide to directly sign the transaction or return the transaction block.
|
|
4445
|
+
* @param obligaionId - The obligation account object.
|
|
4446
|
+
* @param obligaionKeyId - The obligation key account object.
|
|
4447
|
+
* @param walletAddress - The wallet address of the owner.
|
|
4448
|
+
* @return Transaction block response or transaction block
|
|
4449
|
+
*/
|
|
4450
|
+
async stakeObligation(coinName, obligaionId, obligaionKeyId, sign = true, walletAddress) {
|
|
4451
|
+
const txBlock = this.builder.createTxBlock();
|
|
4452
|
+
const sender = walletAddress || this.walletAddress;
|
|
4453
|
+
txBlock.setSender(sender);
|
|
4454
|
+
await txBlock.stakeObligationQuick(coinName, obligaionId, obligaionKeyId);
|
|
4455
|
+
if (sign) {
|
|
4456
|
+
return await this.suiKit.signAndSendTxn(
|
|
4457
|
+
txBlock
|
|
4458
|
+
);
|
|
4459
|
+
} else {
|
|
4460
|
+
return txBlock.txBlock;
|
|
4461
|
+
}
|
|
4462
|
+
}
|
|
4463
|
+
/**
|
|
4464
|
+
* unstake obligaion.
|
|
4465
|
+
*
|
|
4466
|
+
* @param sign - Decide to directly sign the transaction or return the transaction block.
|
|
4467
|
+
* @param obligaionId - The obligation account object.
|
|
4468
|
+
* @param obligaionKeyId - The obligation key account object.
|
|
4469
|
+
* @param walletAddress - The wallet address of the owner.
|
|
4470
|
+
* @return Transaction block response or transaction block
|
|
4471
|
+
*/
|
|
4472
|
+
async unstakeObligation(coinName, obligaionId, obligaionKeyId, sign = true, walletAddress) {
|
|
4473
|
+
const txBlock = this.builder.createTxBlock();
|
|
4474
|
+
const sender = walletAddress || this.walletAddress;
|
|
4475
|
+
txBlock.setSender(sender);
|
|
4476
|
+
await txBlock.unstakeObligationQuick(coinName, obligaionId, obligaionKeyId);
|
|
4477
|
+
if (sign) {
|
|
4478
|
+
return await this.suiKit.signAndSendTxn(
|
|
4479
|
+
txBlock
|
|
4480
|
+
);
|
|
4481
|
+
} else {
|
|
4482
|
+
return txBlock.txBlock;
|
|
4483
|
+
}
|
|
4484
|
+
}
|
|
4485
|
+
/**
|
|
4486
|
+
* unstake market coin from the specific spool.
|
|
4487
|
+
*
|
|
4488
|
+
* @param marketCoinName - Types of mak coin.
|
|
4489
|
+
* @param amount - The amount of coins would deposit.
|
|
4490
|
+
* @param sign - Decide to directly sign the transaction or return the transaction block.
|
|
4491
|
+
* @param accountId - The stake account object.
|
|
4492
|
+
* @param walletAddress - The wallet address of the owner.
|
|
4493
|
+
* @return Transaction block response or transaction block
|
|
4494
|
+
*/
|
|
4495
|
+
async claimBorrowIncentive(coinName, obligaionId, obligaionKeyId, sign = true, walletAddress) {
|
|
4496
|
+
const txBlock = this.builder.createTxBlock();
|
|
4497
|
+
const sender = walletAddress || this.walletAddress;
|
|
4498
|
+
txBlock.setSender(sender);
|
|
4499
|
+
const rewardCoin = await txBlock.claimBorrowIncentiveQuick(
|
|
4500
|
+
coinName,
|
|
4501
|
+
obligaionId,
|
|
4502
|
+
obligaionKeyId
|
|
4503
|
+
);
|
|
4504
|
+
txBlock.transferObjects([rewardCoin], sender);
|
|
3894
4505
|
if (sign) {
|
|
3895
4506
|
return await this.suiKit.signAndSendTxn(
|
|
3896
4507
|
txBlock
|
|
@@ -3925,7 +4536,7 @@ var ScallopClient = class {
|
|
|
3925
4536
|
var Scallop = class {
|
|
3926
4537
|
constructor(params) {
|
|
3927
4538
|
this.params = params;
|
|
3928
|
-
this.suiKit = new
|
|
4539
|
+
this.suiKit = new import_sui_kit10.SuiKit(params);
|
|
3929
4540
|
this._address = new ScallopAddress({
|
|
3930
4541
|
id: params?.addressesId || ADDRESSES_ID,
|
|
3931
4542
|
network: params?.networkType
|
|
@@ -4004,12 +4615,14 @@ var Scallop = class {
|
|
|
4004
4615
|
ADDRESSES_ID,
|
|
4005
4616
|
API_BASE_URL,
|
|
4006
4617
|
PROTOCOL_OBJECT_ID,
|
|
4618
|
+
SUPPORT_BORROW_INCENTIVE_POOLS,
|
|
4619
|
+
SUPPORT_BORROW_INCENTIVE_REWARDS,
|
|
4007
4620
|
SUPPORT_COLLATERALS,
|
|
4008
4621
|
SUPPORT_ORACLES,
|
|
4009
4622
|
SUPPORT_PACKAGES,
|
|
4010
4623
|
SUPPORT_POOLS,
|
|
4011
|
-
SUPPORT_REWARD_POOLS,
|
|
4012
4624
|
SUPPORT_SPOOLS,
|
|
4625
|
+
SUPPORT_SPOOLS_REWARDS,
|
|
4013
4626
|
Scallop,
|
|
4014
4627
|
ScallopAddress,
|
|
4015
4628
|
ScallopBuilder,
|
|
@@ -4017,11 +4630,13 @@ var Scallop = class {
|
|
|
4017
4630
|
ScallopQuery,
|
|
4018
4631
|
ScallopUtils,
|
|
4019
4632
|
assetCoins,
|
|
4633
|
+
borrowIncentiveRewardCoins,
|
|
4020
4634
|
coinDecimals,
|
|
4021
4635
|
coinIds,
|
|
4022
4636
|
marketCoins,
|
|
4023
|
-
|
|
4637
|
+
spoolRewardCoins,
|
|
4024
4638
|
stakeMarketCoins,
|
|
4639
|
+
voloCoinIds,
|
|
4025
4640
|
wormholeCoinIds
|
|
4026
4641
|
});
|
|
4027
4642
|
//# sourceMappingURL=index.js.map
|