@scallop-io/sui-scallop-sdk 0.44.17 → 0.44.19
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 +7 -0
- package/dist/builders/vescaBuilder.d.ts +24 -0
- package/dist/constants/common.d.ts +7 -4
- package/dist/constants/index.d.ts +1 -0
- package/dist/constants/vesca.d.ts +5 -0
- package/dist/index.js +878 -255
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +867 -248
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopClient.d.ts +7 -7
- package/dist/models/scallopUtils.d.ts +16 -14
- package/dist/queries/index.d.ts +1 -0
- package/dist/queries/vescaQuery.d.ts +28 -0
- package/dist/types/address.d.ts +9 -0
- package/dist/types/builder/borrowIncentive.d.ts +9 -6
- package/dist/types/builder/index.d.ts +3 -1
- package/dist/types/builder/vesca.d.ts +33 -0
- package/dist/types/constant/enum.d.ts +1 -1
- package/dist/types/query/borrowIncentive.d.ts +65 -60
- package/dist/types/query/index.d.ts +1 -0
- package/dist/types/query/portfolio.d.ts +12 -6
- package/dist/types/query/vesca.d.ts +7 -0
- package/dist/types/utils.d.ts +1 -2
- package/dist/utils/builder.d.ts +6 -0
- package/dist/utils/query.d.ts +4 -10
- package/dist/utils/util.d.ts +7 -0
- package/package.json +1 -1
- package/src/builders/borrowIncentiveBuilder.ts +174 -25
- package/src/builders/index.ts +6 -2
- package/src/builders/vescaBuilder.ts +392 -0
- package/src/constants/common.ts +19 -6
- package/src/constants/enum.ts +9 -3
- package/src/constants/index.ts +1 -0
- package/src/constants/vesca.ts +7 -0
- package/src/models/scallopAddress.ts +9 -1
- package/src/models/scallopClient.ts +29 -20
- package/src/models/scallopUtils.ts +45 -0
- package/src/queries/borrowIncentiveQuery.ts +93 -83
- package/src/queries/coreQuery.ts +19 -20
- package/src/queries/index.ts +1 -0
- package/src/queries/portfolioQuery.ts +79 -41
- package/src/queries/spoolQuery.ts +1 -1
- package/src/queries/vescaQuery.ts +124 -0
- package/src/types/address.ts +9 -0
- package/src/types/builder/borrowIncentive.ts +22 -5
- package/src/types/builder/index.ts +4 -1
- package/src/types/builder/vesca.ts +73 -0
- package/src/types/constant/enum.ts +1 -1
- package/src/types/query/borrowIncentive.ts +195 -74
- package/src/types/query/index.ts +1 -0
- package/src/types/query/portfolio.ts +17 -6
- package/src/types/query/vesca.ts +7 -0
- package/src/types/utils.ts +1 -1
- package/src/utils/builder.ts +141 -0
- package/src/utils/query.ts +227 -131
- package/src/utils/util.ts +28 -0
package/dist/index.js
CHANGED
|
@@ -33,7 +33,14 @@ __export(src_exports, {
|
|
|
33
33
|
ADDRESSES_ID: () => ADDRESSES_ID,
|
|
34
34
|
API_BASE_URL: () => API_BASE_URL,
|
|
35
35
|
BORROW_FEE_PROTOCOL_ID: () => BORROW_FEE_PROTOCOL_ID,
|
|
36
|
+
IS_VE_SCA_TEST: () => IS_VE_SCA_TEST,
|
|
37
|
+
MAX_LOCK_DURATION: () => MAX_LOCK_DURATION,
|
|
38
|
+
MAX_LOCK_ROUNDS: () => MAX_LOCK_ROUNDS,
|
|
39
|
+
MIN_INITIAL_LOCK_AMOUNT: () => MIN_INITIAL_LOCK_AMOUNT,
|
|
40
|
+
MIN_TOP_UP_AMOUNT: () => MIN_TOP_UP_AMOUNT,
|
|
41
|
+
OLD_BORROW_INCENTIVE_PROTOCOL_ID: () => OLD_BORROW_INCENTIVE_PROTOCOL_ID,
|
|
36
42
|
PROTOCOL_OBJECT_ID: () => PROTOCOL_OBJECT_ID,
|
|
43
|
+
SCA_COIN_TYPE: () => SCA_COIN_TYPE,
|
|
37
44
|
SDK_API_BASE_URL: () => SDK_API_BASE_URL,
|
|
38
45
|
SUPPORT_BORROW_INCENTIVE_POOLS: () => SUPPORT_BORROW_INCENTIVE_POOLS,
|
|
39
46
|
SUPPORT_BORROW_INCENTIVE_REWARDS: () => SUPPORT_BORROW_INCENTIVE_REWARDS,
|
|
@@ -50,6 +57,7 @@ __export(src_exports, {
|
|
|
50
57
|
ScallopIndexer: () => ScallopIndexer,
|
|
51
58
|
ScallopQuery: () => ScallopQuery,
|
|
52
59
|
ScallopUtils: () => ScallopUtils,
|
|
60
|
+
UNLOCK_ROUND_DURATION: () => UNLOCK_ROUND_DURATION,
|
|
53
61
|
assetCoins: () => assetCoins,
|
|
54
62
|
borrowIncentiveRewardCoins: () => borrowIncentiveRewardCoins,
|
|
55
63
|
coinDecimals: () => coinDecimals,
|
|
@@ -65,9 +73,12 @@ module.exports = __toCommonJS(src_exports);
|
|
|
65
73
|
// src/constants/common.ts
|
|
66
74
|
var API_BASE_URL = "https://sui.api.scallop.io";
|
|
67
75
|
var SDK_API_BASE_URL = "https://sdk.api.scallop.io";
|
|
68
|
-
var
|
|
69
|
-
var
|
|
70
|
-
var
|
|
76
|
+
var IS_VE_SCA_TEST = false;
|
|
77
|
+
var ADDRESSES_ID = IS_VE_SCA_TEST ? "65fb07c39c845425d71d7b18" : "6601955b8b0024600a917079";
|
|
78
|
+
var PROTOCOL_OBJECT_ID = IS_VE_SCA_TEST ? "0xc9f859f98ca352a11b97a038c4b4162bee437b8df8caa047990fe9cb03d4f778" : "0xefe8b36d5b2e43728cc323298626b83177803521d195cfb11e15b910e892fddf";
|
|
79
|
+
var BORROW_FEE_PROTOCOL_ID = IS_VE_SCA_TEST ? "0xc9f859f98ca352a11b97a038c4b4162bee437b8df8caa047990fe9cb03d4f778" : "0xc38f849e81cfe46d4e4320f508ea7dda42934a329d5a6571bb4c3cb6ea63f5da";
|
|
80
|
+
var SCA_COIN_TYPE = IS_VE_SCA_TEST ? `0x6cd813061a3adf3602b76545f076205f0c8e7ec1d3b1eab9a1da7992c18c0524::sca::SCA` : "0x7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6::sca::SCA";
|
|
81
|
+
var OLD_BORROW_INCENTIVE_PROTOCOL_ID = "0xc63072e7f5f4983a2efaf5bdba1480d5e7d74d57948e1c7cc436f8e22cbeb410";
|
|
71
82
|
var SUPPORT_POOLS = [
|
|
72
83
|
"eth",
|
|
73
84
|
"btc",
|
|
@@ -106,7 +117,7 @@ var SUPPORT_SPOOLS = [
|
|
|
106
117
|
];
|
|
107
118
|
var SUPPORT_SPOOLS_REWARDS = ["sui"];
|
|
108
119
|
var SUPPORT_BORROW_INCENTIVE_POOLS = ["sui", "usdc", "usdt"];
|
|
109
|
-
var SUPPORT_BORROW_INCENTIVE_REWARDS = ["sui"];
|
|
120
|
+
var SUPPORT_BORROW_INCENTIVE_REWARDS = ["sui", "sca"];
|
|
110
121
|
var SUPPORT_ORACLES = ["supra", "switchboard", "pyth"];
|
|
111
122
|
var SUPPORT_PACKAGES = [
|
|
112
123
|
"coinDecimalsRegistry",
|
|
@@ -146,7 +157,8 @@ var coinDecimals = {
|
|
|
146
157
|
scetus: 9,
|
|
147
158
|
safsui: 9,
|
|
148
159
|
shasui: 9,
|
|
149
|
-
svsui: 9
|
|
160
|
+
svsui: 9,
|
|
161
|
+
sca: 9
|
|
150
162
|
};
|
|
151
163
|
var assetCoins = {
|
|
152
164
|
eth: "eth",
|
|
@@ -159,7 +171,8 @@ var assetCoins = {
|
|
|
159
171
|
cetus: "cetus",
|
|
160
172
|
afsui: "afsui",
|
|
161
173
|
hasui: "hasui",
|
|
162
|
-
vsui: "vsui"
|
|
174
|
+
vsui: "vsui",
|
|
175
|
+
sca: "sca"
|
|
163
176
|
};
|
|
164
177
|
var marketCoins = {
|
|
165
178
|
seth: "seth",
|
|
@@ -195,9 +208,9 @@ var spoolRewardCoins = {
|
|
|
195
208
|
svsui: "sui"
|
|
196
209
|
};
|
|
197
210
|
var borrowIncentiveRewardCoins = {
|
|
198
|
-
sui: "sui",
|
|
199
|
-
usdc: "sui",
|
|
200
|
-
usdt: "sui"
|
|
211
|
+
sui: ["sui", "sca"],
|
|
212
|
+
usdc: ["sui", "sca"],
|
|
213
|
+
usdt: ["sui", "sca"]
|
|
201
214
|
};
|
|
202
215
|
var coinIds = {
|
|
203
216
|
sui: "0x0000000000000000000000000000000000000000000000000000000000000002",
|
|
@@ -210,7 +223,8 @@ var coinIds = {
|
|
|
210
223
|
cetus: "0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b",
|
|
211
224
|
afsui: "0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc",
|
|
212
225
|
hasui: "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d",
|
|
213
|
-
vsui: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55"
|
|
226
|
+
vsui: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55",
|
|
227
|
+
sca: IS_VE_SCA_TEST ? "0x6cd813061a3adf3602b76545f076205f0c8e7ec1d3b1eab9a1da7992c18c0524" : "0x7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6"
|
|
214
228
|
};
|
|
215
229
|
var wormholeCoinIds = {
|
|
216
230
|
eth: "0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5",
|
|
@@ -224,8 +238,15 @@ var voloCoinIds = {
|
|
|
224
238
|
vsui: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55"
|
|
225
239
|
};
|
|
226
240
|
|
|
241
|
+
// src/constants/vesca.ts
|
|
242
|
+
var UNLOCK_ROUND_DURATION = 60 * 60 * 24;
|
|
243
|
+
var MAX_LOCK_ROUNDS = 1460;
|
|
244
|
+
var MAX_LOCK_DURATION = MAX_LOCK_ROUNDS * UNLOCK_ROUND_DURATION;
|
|
245
|
+
var MIN_INITIAL_LOCK_AMOUNT = 1e10;
|
|
246
|
+
var MIN_TOP_UP_AMOUNT = 1e9;
|
|
247
|
+
|
|
227
248
|
// src/models/scallop.ts
|
|
228
|
-
var
|
|
249
|
+
var import_sui_kit11 = require("@scallop-io/sui-kit");
|
|
229
250
|
|
|
230
251
|
// src/models/scallopAddress.ts
|
|
231
252
|
var import_axios = __toESM(require("axios"));
|
|
@@ -452,8 +473,17 @@ var EMPTY_ADDRESSES = {
|
|
|
452
473
|
adminCap: "",
|
|
453
474
|
object: "",
|
|
454
475
|
query: "",
|
|
476
|
+
config: "",
|
|
455
477
|
incentivePools: "",
|
|
456
478
|
incentiveAccounts: ""
|
|
479
|
+
},
|
|
480
|
+
vesca: {
|
|
481
|
+
id: "",
|
|
482
|
+
adminCap: "",
|
|
483
|
+
tableId: "",
|
|
484
|
+
table: "",
|
|
485
|
+
treasury: "",
|
|
486
|
+
config: ""
|
|
457
487
|
}
|
|
458
488
|
};
|
|
459
489
|
var ScallopAddress = class {
|
|
@@ -757,8 +787,8 @@ var ScallopAddress = class {
|
|
|
757
787
|
};
|
|
758
788
|
|
|
759
789
|
// src/models/scallopClient.ts
|
|
760
|
-
var
|
|
761
|
-
var
|
|
790
|
+
var import_utils20 = require("@mysten/sui.js/utils");
|
|
791
|
+
var import_sui_kit10 = require("@scallop-io/sui-kit");
|
|
762
792
|
|
|
763
793
|
// src/models/scallopUtils.ts
|
|
764
794
|
var import_utils9 = require("@mysten/sui.js/utils");
|
|
@@ -781,6 +811,92 @@ var requireSender = (txBlock) => {
|
|
|
781
811
|
}
|
|
782
812
|
return sender;
|
|
783
813
|
};
|
|
814
|
+
var checkLockSca = (scaAmountOrCoin, lockPeriodInDays, newUnlockAtInSecondTimestamp, prevUnlockAtInSecondTimestamp) => {
|
|
815
|
+
const isInitialLock = !prevUnlockAtInSecondTimestamp;
|
|
816
|
+
const isLockExpired = !isInitialLock && prevUnlockAtInSecondTimestamp * 1e3 <= (/* @__PURE__ */ new Date()).getTime();
|
|
817
|
+
if (isInitialLock || isLockExpired) {
|
|
818
|
+
if (scaAmountOrCoin !== void 0 && lockPeriodInDays !== void 0) {
|
|
819
|
+
if (lockPeriodInDays <= 0) {
|
|
820
|
+
throw new Error("Lock period must be greater than 0");
|
|
821
|
+
}
|
|
822
|
+
if (typeof scaAmountOrCoin === "number" && scaAmountOrCoin < MIN_INITIAL_LOCK_AMOUNT) {
|
|
823
|
+
throw new Error(
|
|
824
|
+
`Minimum lock amount for ${isLockExpired ? "renewing expired veSca" : "initial lock"} is 10 SCA`
|
|
825
|
+
);
|
|
826
|
+
}
|
|
827
|
+
const extendLockPeriodInSecond = lockPeriodInDays * UNLOCK_ROUND_DURATION;
|
|
828
|
+
if (extendLockPeriodInSecond > MAX_LOCK_DURATION) {
|
|
829
|
+
throw new Error(
|
|
830
|
+
`Maximum lock period is ~4 years (${MAX_LOCK_ROUNDS} days)`
|
|
831
|
+
);
|
|
832
|
+
}
|
|
833
|
+
} else {
|
|
834
|
+
throw new Error(
|
|
835
|
+
`SCA amount and lock period is required for ${isLockExpired ? "renewing expired veSca" : "initial lock"}`
|
|
836
|
+
);
|
|
837
|
+
}
|
|
838
|
+
} else {
|
|
839
|
+
checkVesca(prevUnlockAtInSecondTimestamp);
|
|
840
|
+
if (typeof scaAmountOrCoin === "number" && scaAmountOrCoin < MIN_TOP_UP_AMOUNT) {
|
|
841
|
+
throw new Error("Minimum top up amount is 1 SCA");
|
|
842
|
+
}
|
|
843
|
+
if (!!newUnlockAtInSecondTimestamp && !!prevUnlockAtInSecondTimestamp) {
|
|
844
|
+
const totalLockDuration = newUnlockAtInSecondTimestamp - prevUnlockAtInSecondTimestamp;
|
|
845
|
+
if (totalLockDuration > MAX_LOCK_DURATION - UNLOCK_ROUND_DURATION) {
|
|
846
|
+
throw new Error(
|
|
847
|
+
`Maximum lock period is ~4 years (${MAX_LOCK_ROUNDS - 1} days)`
|
|
848
|
+
);
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
};
|
|
853
|
+
var checkExtendLockPeriod = (lockPeriodInDays, newUnlockAtInSecondTimestamp, prevUnlockAtInSecondTimestamp) => {
|
|
854
|
+
checkVesca(prevUnlockAtInSecondTimestamp);
|
|
855
|
+
if (lockPeriodInDays <= 0) {
|
|
856
|
+
throw new Error("Lock period must be greater than 0");
|
|
857
|
+
}
|
|
858
|
+
const isInitialLock = !prevUnlockAtInSecondTimestamp;
|
|
859
|
+
const isLockExpired = !isInitialLock && prevUnlockAtInSecondTimestamp * 1e3 <= (/* @__PURE__ */ new Date()).getTime();
|
|
860
|
+
if (isLockExpired) {
|
|
861
|
+
throw new Error("veSca is expired, use renewExpiredVeScaQuick instead");
|
|
862
|
+
}
|
|
863
|
+
if (prevUnlockAtInSecondTimestamp) {
|
|
864
|
+
const totalLockDuration = newUnlockAtInSecondTimestamp - prevUnlockAtInSecondTimestamp;
|
|
865
|
+
if (totalLockDuration > MAX_LOCK_DURATION - UNLOCK_ROUND_DURATION) {
|
|
866
|
+
throw new Error(
|
|
867
|
+
`Maximum lock period is ~4 years (${MAX_LOCK_ROUNDS - 1} days)`
|
|
868
|
+
);
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
};
|
|
872
|
+
var checkExtendLockAmount = (scaAmount, prevUnlockAtInSecondTimestamp) => {
|
|
873
|
+
checkVesca(prevUnlockAtInSecondTimestamp);
|
|
874
|
+
if (scaAmount < MIN_TOP_UP_AMOUNT) {
|
|
875
|
+
throw new Error("Minimum top up amount is 1 SCA");
|
|
876
|
+
}
|
|
877
|
+
const isInitialLock = !prevUnlockAtInSecondTimestamp;
|
|
878
|
+
const isLockExpired = !isInitialLock && prevUnlockAtInSecondTimestamp * 1e3 <= (/* @__PURE__ */ new Date()).getTime();
|
|
879
|
+
if (isLockExpired) {
|
|
880
|
+
throw new Error("veSca is expired, use renewExpiredVeScaQuick instead");
|
|
881
|
+
}
|
|
882
|
+
};
|
|
883
|
+
var checkRenewExpiredVeSca = (scaAmount, lockPeriodInDays, prevUnlockAtInSecondTimestamp) => {
|
|
884
|
+
checkVesca(prevUnlockAtInSecondTimestamp);
|
|
885
|
+
if (scaAmount < MIN_INITIAL_LOCK_AMOUNT) {
|
|
886
|
+
throw new Error("Minimum lock amount for renewing expired vesca 10 SCA");
|
|
887
|
+
}
|
|
888
|
+
const extendLockPeriodInSecond = lockPeriodInDays * UNLOCK_ROUND_DURATION;
|
|
889
|
+
if (extendLockPeriodInSecond >= MAX_LOCK_DURATION - UNLOCK_ROUND_DURATION) {
|
|
890
|
+
throw new Error(
|
|
891
|
+
`Maximum lock period is ~4 years (${MAX_LOCK_ROUNDS - 1} days)`
|
|
892
|
+
);
|
|
893
|
+
}
|
|
894
|
+
};
|
|
895
|
+
var checkVesca = (prevUnlockAtInSecondTimestamp) => {
|
|
896
|
+
if (prevUnlockAtInSecondTimestamp === void 0) {
|
|
897
|
+
throw new Error("veSca not found");
|
|
898
|
+
}
|
|
899
|
+
};
|
|
784
900
|
|
|
785
901
|
// src/utils/query.ts
|
|
786
902
|
var import_bignumber = __toESM(require("bignumber.js"));
|
|
@@ -1000,7 +1116,10 @@ var calculateSpoolRewardPoolData = (parsedSpoolData, parsedSpoolRewardPoolData,
|
|
|
1000
1116
|
);
|
|
1001
1117
|
const claimedRewardValue = claimedRewardCoin.multipliedBy(rewardCoinPrice);
|
|
1002
1118
|
const rewardValueForYear = (0, import_bignumber.default)(rewardPerSec).shiftedBy(-1 * rewardCoinDecimal).multipliedBy(rateYearFactor).multipliedBy(rewardCoinPrice);
|
|
1003
|
-
|
|
1119
|
+
let rewardRate = rewardValueForYear.dividedBy(calculatedSpoolData.stakedValue).isFinite() ? rewardValueForYear.dividedBy(calculatedSpoolData.stakedValue).toNumber() : Infinity;
|
|
1120
|
+
if (parsedSpoolData.maxPoint === parsedSpoolData.distributedPoint) {
|
|
1121
|
+
rewardRate = Infinity;
|
|
1122
|
+
}
|
|
1004
1123
|
return {
|
|
1005
1124
|
rewardApr: rewardRate,
|
|
1006
1125
|
totalRewardAmount: totalRewardAmount.toNumber(),
|
|
@@ -1015,119 +1134,112 @@ var calculateSpoolRewardPoolData = (parsedSpoolData, parsedSpoolRewardPoolData,
|
|
|
1015
1134
|
rewardPerSec: rewardPerSec.toNumber()
|
|
1016
1135
|
};
|
|
1017
1136
|
};
|
|
1137
|
+
var parseOriginBorrowIncentivesPoolPointData = (originBorrowIncentivePoolPointData) => {
|
|
1138
|
+
return {
|
|
1139
|
+
pointType: (0, import_utils.normalizeStructTag)(
|
|
1140
|
+
originBorrowIncentivePoolPointData.point_type.name
|
|
1141
|
+
),
|
|
1142
|
+
distributedPointPerPeriod: Number(
|
|
1143
|
+
originBorrowIncentivePoolPointData.distributed_point_per_period
|
|
1144
|
+
),
|
|
1145
|
+
period: Number(originBorrowIncentivePoolPointData.point_distribution_time),
|
|
1146
|
+
distributedPoint: Number(
|
|
1147
|
+
originBorrowIncentivePoolPointData.distributed_point
|
|
1148
|
+
),
|
|
1149
|
+
points: Number(originBorrowIncentivePoolPointData.points),
|
|
1150
|
+
index: Number(originBorrowIncentivePoolPointData.index),
|
|
1151
|
+
baseWeight: Number(originBorrowIncentivePoolPointData.base_weight),
|
|
1152
|
+
weightedAmount: Number(originBorrowIncentivePoolPointData.weighted_amount),
|
|
1153
|
+
lastUpdate: Number(originBorrowIncentivePoolPointData.last_update)
|
|
1154
|
+
};
|
|
1155
|
+
};
|
|
1018
1156
|
var parseOriginBorrowIncentivePoolData = (originBorrowIncentivePoolData) => {
|
|
1019
1157
|
return {
|
|
1020
1158
|
poolType: (0, import_utils.normalizeStructTag)(originBorrowIncentivePoolData.pool_type.name),
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
pointPerPeriod: Number(
|
|
1024
|
-
originBorrowIncentivePoolData.distributed_point_per_period
|
|
1025
|
-
),
|
|
1026
|
-
period: Number(originBorrowIncentivePoolData.point_distribution_time),
|
|
1027
|
-
maxStake: Number(originBorrowIncentivePoolData.max_stakes),
|
|
1159
|
+
minStakes: Number(originBorrowIncentivePoolData.min_stakes),
|
|
1160
|
+
maxStakes: Number(originBorrowIncentivePoolData.max_stakes),
|
|
1028
1161
|
staked: Number(originBorrowIncentivePoolData.stakes),
|
|
1029
|
-
index: Number(originBorrowIncentivePoolData.index),
|
|
1030
1162
|
createdAt: Number(originBorrowIncentivePoolData.created_at),
|
|
1031
|
-
|
|
1163
|
+
poolPoints: originBorrowIncentivePoolData.points.reduce(
|
|
1164
|
+
(acc, point) => {
|
|
1165
|
+
const parsed = parseOriginBorrowIncentivesPoolPointData(point);
|
|
1166
|
+
const name = (0, import_utils.parseStructTag)(
|
|
1167
|
+
parsed.pointType
|
|
1168
|
+
).name.toLowerCase();
|
|
1169
|
+
acc[name] = parsed;
|
|
1170
|
+
return acc;
|
|
1171
|
+
},
|
|
1172
|
+
{}
|
|
1173
|
+
)
|
|
1032
1174
|
};
|
|
1033
1175
|
};
|
|
1034
|
-
var
|
|
1176
|
+
var calculateBorrowIncentivePoolPointData = (pasredBorrowIncentinvePoolData, parsedBorrowIncentivePoolPointData, rewardCoinPrice, rewardCoinDecimal, poolCoinPrice, poolCoinDecimal) => {
|
|
1035
1177
|
const baseIndexRate = 1e9;
|
|
1036
1178
|
const distributedPointPerSec = (0, import_bignumber.default)(
|
|
1037
|
-
|
|
1038
|
-
).dividedBy(
|
|
1039
|
-
const pointPerSec = (0, import_bignumber.default)(
|
|
1040
|
-
parsedBorrowIncentivePoolData.pointPerPeriod
|
|
1041
|
-
).dividedBy(parsedBorrowIncentivePoolData.period);
|
|
1042
|
-
const remainingPeriod = (0, import_bignumber.default)(parsedBorrowIncentivePoolData.maxPoint).minus(parsedBorrowIncentivePoolData.distributedPoint).dividedBy(pointPerSec);
|
|
1043
|
-
const startDate = parsedBorrowIncentivePoolData.createdAt;
|
|
1044
|
-
const endDate = remainingPeriod.plus(parsedBorrowIncentivePoolData.lastUpdate).integerValue().toNumber();
|
|
1179
|
+
parsedBorrowIncentivePoolPointData.distributedPointPerPeriod
|
|
1180
|
+
).dividedBy(parsedBorrowIncentivePoolPointData.period);
|
|
1045
1181
|
const timeDelta = (0, import_bignumber.default)(
|
|
1046
|
-
Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) -
|
|
1047
|
-
).dividedBy(
|
|
1048
|
-
const remainingPoints = (0, import_bignumber.default)(
|
|
1049
|
-
parsedBorrowIncentivePoolData.maxPoint
|
|
1050
|
-
).minus(parsedBorrowIncentivePoolData.distributedPoint);
|
|
1182
|
+
Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) - parsedBorrowIncentivePoolPointData.lastUpdate
|
|
1183
|
+
).dividedBy(parsedBorrowIncentivePoolPointData.period).toFixed(0);
|
|
1051
1184
|
const accumulatedPoints = import_bignumber.default.minimum(
|
|
1052
1185
|
(0, import_bignumber.default)(timeDelta).multipliedBy(
|
|
1053
|
-
|
|
1186
|
+
parsedBorrowIncentivePoolPointData.distributedPointPerPeriod
|
|
1054
1187
|
),
|
|
1055
|
-
|
|
1188
|
+
(0, import_bignumber.default)(parsedBorrowIncentivePoolPointData.points)
|
|
1056
1189
|
);
|
|
1057
|
-
const currentPointIndex = (0, import_bignumber.default)(
|
|
1058
|
-
|
|
1190
|
+
const currentPointIndex = (0, import_bignumber.default)(
|
|
1191
|
+
parsedBorrowIncentivePoolPointData.index
|
|
1192
|
+
).plus(
|
|
1193
|
+
accumulatedPoints.dividedBy(parsedBorrowIncentivePoolPointData.weightedAmount).isFinite() ? (0, import_bignumber.default)(baseIndexRate).multipliedBy(accumulatedPoints).dividedBy(parsedBorrowIncentivePoolPointData.weightedAmount) : 0
|
|
1059
1194
|
);
|
|
1060
1195
|
const currentTotalDistributedPoint = (0, import_bignumber.default)(
|
|
1061
|
-
|
|
1196
|
+
parsedBorrowIncentivePoolPointData.distributedPoint
|
|
1062
1197
|
).plus(accumulatedPoints);
|
|
1063
|
-
const stakedAmount = (0, import_bignumber.default)(
|
|
1064
|
-
const stakedCoin = stakedAmount.shiftedBy(-1 *
|
|
1065
|
-
const stakedValue = stakedCoin.multipliedBy(
|
|
1198
|
+
const stakedAmount = (0, import_bignumber.default)(pasredBorrowIncentinvePoolData.staked);
|
|
1199
|
+
const stakedCoin = stakedAmount.shiftedBy(-1 * poolCoinDecimal);
|
|
1200
|
+
const stakedValue = stakedCoin.multipliedBy(poolCoinPrice);
|
|
1201
|
+
const baseWeight = (0, import_bignumber.default)(parsedBorrowIncentivePoolPointData.baseWeight);
|
|
1202
|
+
const weightedStakedAmount = (0, import_bignumber.default)(
|
|
1203
|
+
parsedBorrowIncentivePoolPointData.weightedAmount
|
|
1204
|
+
);
|
|
1205
|
+
const weightedStakedCoin = weightedStakedAmount.shiftedBy(
|
|
1206
|
+
-1 * poolCoinDecimal
|
|
1207
|
+
);
|
|
1208
|
+
const weightedStakedValue = weightedStakedCoin.multipliedBy(poolCoinPrice);
|
|
1209
|
+
const rateYearFactor = 365 * 24 * 60 * 60;
|
|
1210
|
+
const rewardPerSec = (0, import_bignumber.default)(distributedPointPerSec).dividedBy(
|
|
1211
|
+
parsedBorrowIncentivePoolPointData.period
|
|
1212
|
+
);
|
|
1213
|
+
const rewardValueForYear = (0, import_bignumber.default)(rewardPerSec).shiftedBy(-1 * rewardCoinDecimal).multipliedBy(rateYearFactor).multipliedBy(rewardCoinPrice);
|
|
1214
|
+
const weightScale = (0, import_bignumber.default)("1000000000000");
|
|
1215
|
+
const rewardRate = rewardValueForYear.dividedBy(weightedStakedValue).multipliedBy(parsedBorrowIncentivePoolPointData.baseWeight).dividedBy(weightScale).isFinite() ? rewardValueForYear.dividedBy(weightedStakedValue).multipliedBy(parsedBorrowIncentivePoolPointData.baseWeight).dividedBy(weightScale).toNumber() : Infinity;
|
|
1066
1216
|
return {
|
|
1067
1217
|
distributedPointPerSec: distributedPointPerSec.toNumber(),
|
|
1068
1218
|
accumulatedPoints: accumulatedPoints.toNumber(),
|
|
1069
1219
|
currentPointIndex: currentPointIndex.toNumber(),
|
|
1070
1220
|
currentTotalDistributedPoint: currentTotalDistributedPoint.toNumber(),
|
|
1071
|
-
startDate: new Date(startDate * 1e3),
|
|
1072
|
-
endDate: new Date(endDate * 1e3),
|
|
1073
1221
|
stakedAmount: stakedAmount.toNumber(),
|
|
1074
1222
|
stakedCoin: stakedCoin.toNumber(),
|
|
1075
|
-
stakedValue: stakedValue.toNumber()
|
|
1223
|
+
stakedValue: stakedValue.toNumber(),
|
|
1224
|
+
baseWeight: baseWeight.toNumber(),
|
|
1225
|
+
weightedStakedAmount: weightedStakedAmount.toNumber(),
|
|
1226
|
+
weightedStakedCoin: weightedStakedCoin.toNumber(),
|
|
1227
|
+
weightedStakedValue: weightedStakedValue.toNumber(),
|
|
1228
|
+
rewardApr: rewardRate,
|
|
1229
|
+
rewardPerSec: rewardPerSec.toNumber()
|
|
1076
1230
|
};
|
|
1077
1231
|
};
|
|
1078
|
-
var
|
|
1232
|
+
var parseOriginBorrowIncentiveAccountPoolPointData = (originBorrowIncentiveAccountPoolPointData) => {
|
|
1079
1233
|
return {
|
|
1080
|
-
|
|
1081
|
-
|
|
1234
|
+
pointType: (0, import_utils.normalizeStructTag)(
|
|
1235
|
+
originBorrowIncentiveAccountPoolPointData.point_type.name
|
|
1082
1236
|
),
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
originBorrowIncentiveRewardPoolData.exchange_rate_numerator
|
|
1086
|
-
),
|
|
1087
|
-
exchangeRateDenominator: Number(
|
|
1088
|
-
originBorrowIncentiveRewardPoolData.exchange_rate_denominator
|
|
1237
|
+
weightedAmount: Number(
|
|
1238
|
+
originBorrowIncentiveAccountPoolPointData.weighted_amount
|
|
1089
1239
|
),
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
)
|
|
1093
|
-
};
|
|
1094
|
-
};
|
|
1095
|
-
var calculateBorrowIncentiveRewardPoolData = (parsedBorrowIncentivePoolData, parsedBorrowIncentiveRewardPoolData, calculatedBorrowIncentivePoolData, rewardCoinPrice, rewardCoinDecimal) => {
|
|
1096
|
-
const rateYearFactor = 365 * 24 * 60 * 60;
|
|
1097
|
-
const rewardPerSec = (0, import_bignumber.default)(
|
|
1098
|
-
calculatedBorrowIncentivePoolData.distributedPointPerSec
|
|
1099
|
-
).multipliedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateNumerator).dividedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateDenominator);
|
|
1100
|
-
const totalRewardAmount = (0, import_bignumber.default)(parsedBorrowIncentivePoolData.maxPoint).multipliedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateNumerator).dividedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateDenominator);
|
|
1101
|
-
const totalRewardCoin = totalRewardAmount.shiftedBy(-1 * rewardCoinDecimal);
|
|
1102
|
-
const totalRewardValue = totalRewardCoin.multipliedBy(rewardCoinPrice);
|
|
1103
|
-
const remaindRewardAmount = (0, import_bignumber.default)(
|
|
1104
|
-
parsedBorrowIncentiveRewardPoolData.remainingRewards
|
|
1105
|
-
);
|
|
1106
|
-
const remaindRewardCoin = remaindRewardAmount.shiftedBy(
|
|
1107
|
-
-1 * rewardCoinDecimal
|
|
1108
|
-
);
|
|
1109
|
-
const remaindRewardValue = remaindRewardCoin.multipliedBy(rewardCoinPrice);
|
|
1110
|
-
const claimedRewardAmount = (0, import_bignumber.default)(
|
|
1111
|
-
parsedBorrowIncentiveRewardPoolData.claimedRewards
|
|
1112
|
-
);
|
|
1113
|
-
const claimedRewardCoin = claimedRewardAmount.shiftedBy(
|
|
1114
|
-
-1 * rewardCoinDecimal
|
|
1115
|
-
);
|
|
1116
|
-
const claimedRewardValue = claimedRewardCoin.multipliedBy(rewardCoinPrice);
|
|
1117
|
-
const rewardValueForYear = (0, import_bignumber.default)(rewardPerSec).shiftedBy(-1 * rewardCoinDecimal).multipliedBy(rateYearFactor).multipliedBy(rewardCoinPrice);
|
|
1118
|
-
const rewardRate = rewardValueForYear.dividedBy(calculatedBorrowIncentivePoolData.stakedValue).isFinite() ? rewardValueForYear.dividedBy(calculatedBorrowIncentivePoolData.stakedValue).toNumber() : Infinity;
|
|
1119
|
-
return {
|
|
1120
|
-
rewardApr: rewardRate,
|
|
1121
|
-
totalRewardAmount: totalRewardAmount.toNumber(),
|
|
1122
|
-
totalRewardCoin: totalRewardCoin.toNumber(),
|
|
1123
|
-
totalRewardValue: totalRewardValue.toNumber(),
|
|
1124
|
-
remaindRewardAmount: remaindRewardAmount.toNumber(),
|
|
1125
|
-
remaindRewardCoin: remaindRewardCoin.toNumber(),
|
|
1126
|
-
remaindRewardValue: remaindRewardValue.toNumber(),
|
|
1127
|
-
claimedRewardAmount: claimedRewardAmount.toNumber(),
|
|
1128
|
-
claimedRewardCoin: claimedRewardCoin.toNumber(),
|
|
1129
|
-
claimedRewardValue: claimedRewardValue.toNumber(),
|
|
1130
|
-
rewardPerSec: rewardPerSec.toNumber()
|
|
1240
|
+
points: Number(originBorrowIncentiveAccountPoolPointData.points),
|
|
1241
|
+
totalPoints: Number(originBorrowIncentiveAccountPoolPointData.total_points),
|
|
1242
|
+
index: Number(originBorrowIncentiveAccountPoolPointData.index)
|
|
1131
1243
|
};
|
|
1132
1244
|
};
|
|
1133
1245
|
var parseOriginBorrowIncentiveAccountData = (originBorrowIncentiveAccountData) => {
|
|
@@ -1135,10 +1247,18 @@ var parseOriginBorrowIncentiveAccountData = (originBorrowIncentiveAccountData) =
|
|
|
1135
1247
|
poolType: (0, import_utils.normalizeStructTag)(
|
|
1136
1248
|
originBorrowIncentiveAccountData.pool_type.name
|
|
1137
1249
|
),
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1250
|
+
debtAmount: Number(originBorrowIncentiveAccountData.debt_amount),
|
|
1251
|
+
pointList: originBorrowIncentiveAccountData.points_list.reduce(
|
|
1252
|
+
(acc, point) => {
|
|
1253
|
+
const parsed = parseOriginBorrowIncentiveAccountPoolPointData(point);
|
|
1254
|
+
const name = (0, import_utils.parseStructTag)(
|
|
1255
|
+
parsed.pointType
|
|
1256
|
+
).name.toLowerCase();
|
|
1257
|
+
acc[name] = parsed;
|
|
1258
|
+
return acc;
|
|
1259
|
+
},
|
|
1260
|
+
{}
|
|
1261
|
+
)
|
|
1142
1262
|
};
|
|
1143
1263
|
};
|
|
1144
1264
|
var minBigNumber = (...args) => {
|
|
@@ -1166,7 +1286,8 @@ var isMarketCoin = (coinName) => {
|
|
|
1166
1286
|
.../* @__PURE__ */ new Set([
|
|
1167
1287
|
...SUPPORT_POOLS,
|
|
1168
1288
|
...SUPPORT_COLLATERALS,
|
|
1169
|
-
...SUPPORT_SPOOLS_REWARDS
|
|
1289
|
+
...SUPPORT_SPOOLS_REWARDS,
|
|
1290
|
+
...SUPPORT_BORROW_INCENTIVE_REWARDS
|
|
1170
1291
|
])
|
|
1171
1292
|
].includes(assetCoinName);
|
|
1172
1293
|
};
|
|
@@ -1200,6 +1321,19 @@ var parseDataFromPythPriceFeed = (feed, address) => {
|
|
|
1200
1321
|
throw new Error("Invalid feed id");
|
|
1201
1322
|
}
|
|
1202
1323
|
};
|
|
1324
|
+
var findClosestUnlockRound = (unlockAtInSecondTimestamp) => {
|
|
1325
|
+
const unlockDate = new Date(unlockAtInSecondTimestamp * 1e3);
|
|
1326
|
+
const closestTwelveAM = new Date(unlockAtInSecondTimestamp * 1e3);
|
|
1327
|
+
closestTwelveAM.setUTCHours(0, 0, 0, 0);
|
|
1328
|
+
if (unlockDate.getUTCHours() >= 0) {
|
|
1329
|
+
closestTwelveAM.setUTCDate(closestTwelveAM.getUTCDate() + 1);
|
|
1330
|
+
}
|
|
1331
|
+
const now = (/* @__PURE__ */ new Date()).getTime();
|
|
1332
|
+
if (closestTwelveAM.getTime() - now > MAX_LOCK_DURATION * 1e3) {
|
|
1333
|
+
closestTwelveAM.setUTCDate(closestTwelveAM.getUTCDate() - 1);
|
|
1334
|
+
}
|
|
1335
|
+
return Math.floor(closestTwelveAM.getTime() / 1e3);
|
|
1336
|
+
};
|
|
1203
1337
|
|
|
1204
1338
|
// src/queries/coreQuery.ts
|
|
1205
1339
|
var queryMarket = async (query, indexer = false) => {
|
|
@@ -1388,7 +1522,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
|
|
|
1388
1522
|
const fields = marketObject.content.fields;
|
|
1389
1523
|
const coinType = query.utils.parseCoinType(poolCoinName);
|
|
1390
1524
|
const balanceSheetParentId = fields.vault.fields.balance_sheets.fields.table.fields.id.id;
|
|
1391
|
-
const
|
|
1525
|
+
const balanceSheetDynamicFieldObjectResponse = await query.suiKit.client().getDynamicFieldObject({
|
|
1392
1526
|
parentId: balanceSheetParentId,
|
|
1393
1527
|
name: {
|
|
1394
1528
|
type: "0x1::type_name::TypeName",
|
|
@@ -1397,9 +1531,9 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
|
|
|
1397
1531
|
}
|
|
1398
1532
|
}
|
|
1399
1533
|
});
|
|
1400
|
-
const
|
|
1401
|
-
if (
|
|
1402
|
-
const dynamicFields =
|
|
1534
|
+
const balanceSheetDynamicFieldObject = balanceSheetDynamicFieldObjectResponse.data;
|
|
1535
|
+
if (balanceSheetDynamicFieldObject && balanceSheetDynamicFieldObject.content && "fields" in balanceSheetDynamicFieldObject.content) {
|
|
1536
|
+
const dynamicFields = balanceSheetDynamicFieldObject.content.fields;
|
|
1403
1537
|
balanceSheet = dynamicFields.value.fields;
|
|
1404
1538
|
}
|
|
1405
1539
|
const borrowIndexParentId = fields.borrow_dynamics.fields.table.fields.id.id;
|
|
@@ -1559,7 +1693,7 @@ var getMarketCollateral = async (query, collateralCoinName, indexer = false, mar
|
|
|
1559
1693
|
const fields = marketObject.content.fields;
|
|
1560
1694
|
const coinType = query.utils.parseCoinType(collateralCoinName);
|
|
1561
1695
|
const riskModelParentId = fields.risk_models.fields.table.fields.id.id;
|
|
1562
|
-
const
|
|
1696
|
+
const riskModelDynamicFieldObjectResponse = await query.suiKit.client().getDynamicFieldObject({
|
|
1563
1697
|
parentId: riskModelParentId,
|
|
1564
1698
|
name: {
|
|
1565
1699
|
type: "0x1::type_name::TypeName",
|
|
@@ -1568,9 +1702,9 @@ var getMarketCollateral = async (query, collateralCoinName, indexer = false, mar
|
|
|
1568
1702
|
}
|
|
1569
1703
|
}
|
|
1570
1704
|
});
|
|
1571
|
-
const
|
|
1572
|
-
if (
|
|
1573
|
-
const dynamicFields =
|
|
1705
|
+
const riskModelDynamicFieldObject = riskModelDynamicFieldObjectResponse.data;
|
|
1706
|
+
if (riskModelDynamicFieldObject && riskModelDynamicFieldObject.content && "fields" in riskModelDynamicFieldObject.content) {
|
|
1707
|
+
const dynamicFields = riskModelDynamicFieldObject.content.fields;
|
|
1574
1708
|
riskModel = dynamicFields.value.fields;
|
|
1575
1709
|
}
|
|
1576
1710
|
const collateralStatParentId = fields.collateral_stats.fields.table.fields.id.id;
|
|
@@ -2240,71 +2374,70 @@ var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames, indexer
|
|
|
2240
2374
|
const incentivePoolsId = query.address.get("borrowIncentive.incentivePools");
|
|
2241
2375
|
const txBlock = new import_sui_kit2.SuiTxBlock();
|
|
2242
2376
|
const queryTarget = `${queryPkgId}::incentive_pools_query::incentive_pools_data`;
|
|
2243
|
-
txBlock.moveCall(queryTarget, [incentivePoolsId]
|
|
2377
|
+
txBlock.moveCall(queryTarget, [incentivePoolsId]);
|
|
2244
2378
|
const queryResult = await query.suiKit.inspectTxn(txBlock);
|
|
2245
2379
|
const borrowIncentivePoolsQueryData = queryResult.events[0].parsedJson;
|
|
2246
|
-
const parsedBorrowIncentiveRewardPoolData = parseOriginBorrowIncentiveRewardPoolData(
|
|
2247
|
-
borrowIncentivePoolsQueryData.reward_pool
|
|
2248
|
-
);
|
|
2249
|
-
const rewardCoinType = parsedBorrowIncentiveRewardPoolData.rewardType;
|
|
2250
|
-
const rewardCoinName = query.utils.parseCoinNameFromType(rewardCoinType);
|
|
2251
|
-
const coinPrices = await query.utils.getCoinPrices(
|
|
2252
|
-
[.../* @__PURE__ */ new Set([...borrowIncentiveCoinNames, rewardCoinName])]
|
|
2253
|
-
);
|
|
2254
2380
|
const borrowIncentivePools = {};
|
|
2255
2381
|
if (indexer) {
|
|
2256
|
-
const borrowIncentivePoolsIndexer = await query.indexer.getBorrowIncentivePools();
|
|
2257
|
-
for (const borrowIncentivePool of Object.values(
|
|
2258
|
-
borrowIncentivePoolsIndexer
|
|
2259
|
-
)) {
|
|
2260
|
-
if (!borrowIncentiveCoinNames.includes(borrowIncentivePool.coinName))
|
|
2261
|
-
continue;
|
|
2262
|
-
borrowIncentivePool.coinPrice = coinPrices[borrowIncentivePool.coinName] || borrowIncentivePool.coinPrice;
|
|
2263
|
-
borrowIncentivePool.rewardCoinPrice = coinPrices[rewardCoinName] || borrowIncentivePool.rewardCoinPrice;
|
|
2264
|
-
borrowIncentivePools[borrowIncentivePool.coinName] = borrowIncentivePool;
|
|
2265
|
-
}
|
|
2266
|
-
return borrowIncentivePools;
|
|
2267
2382
|
}
|
|
2268
2383
|
for (const pool of borrowIncentivePoolsQueryData.incentive_pools) {
|
|
2269
|
-
const
|
|
2270
|
-
const coinName = query.utils.parseCoinNameFromType(coinType);
|
|
2271
|
-
const rewardCoinName2 = query.utils.parseCoinNameFromType(rewardCoinType);
|
|
2272
|
-
if (!borrowIncentiveCoinNames.includes(coinName)) {
|
|
2273
|
-
continue;
|
|
2274
|
-
}
|
|
2384
|
+
const borrowIncentivePoolPoints = {};
|
|
2275
2385
|
const parsedBorrowIncentivePoolData = parseOriginBorrowIncentivePoolData(pool);
|
|
2276
|
-
const
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2386
|
+
const coinPrices = await query.utils.getCoinPrices(
|
|
2387
|
+
[
|
|
2388
|
+
.../* @__PURE__ */ new Set([
|
|
2389
|
+
...borrowIncentiveCoinNames,
|
|
2390
|
+
...SUPPORT_BORROW_INCENTIVE_REWARDS
|
|
2391
|
+
])
|
|
2392
|
+
]
|
|
2282
2393
|
);
|
|
2283
|
-
const
|
|
2284
|
-
const
|
|
2285
|
-
|
|
2286
|
-
parsedBorrowIncentivePoolData,
|
|
2287
|
-
parsedBorrowIncentiveRewardPoolData,
|
|
2288
|
-
calculatedBorrowIncentivePoolData,
|
|
2289
|
-
rewardCoinPrice,
|
|
2290
|
-
rewardCoinDecimal
|
|
2394
|
+
const poolCoinType = (0, import_utils6.normalizeStructTag)(pool.pool_type.name);
|
|
2395
|
+
const poolCoinName = query.utils.parseCoinNameFromType(
|
|
2396
|
+
poolCoinType
|
|
2291
2397
|
);
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2398
|
+
const poolCoinPrice = coinPrices?.[poolCoinName] ?? 0;
|
|
2399
|
+
const poolCoinDecimal = query.utils.getCoinDecimal(poolCoinName);
|
|
2400
|
+
if (!borrowIncentiveCoinNames.includes(poolCoinName)) {
|
|
2401
|
+
continue;
|
|
2402
|
+
}
|
|
2403
|
+
for (const [coinName, poolPoint] of Object.entries(
|
|
2404
|
+
parsedBorrowIncentivePoolData.poolPoints
|
|
2405
|
+
)) {
|
|
2406
|
+
const rewardCoinType = (0, import_utils6.normalizeStructTag)(poolPoint.pointType);
|
|
2407
|
+
const rewardCoinName = query.utils.parseCoinNameFromType(
|
|
2408
|
+
rewardCoinType
|
|
2409
|
+
);
|
|
2410
|
+
const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
|
|
2411
|
+
const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
2412
|
+
const symbol = query.utils.parseSymbol(rewardCoinName);
|
|
2413
|
+
const coinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
2414
|
+
const calculatedPoolPoint = calculateBorrowIncentivePoolPointData(
|
|
2415
|
+
parsedBorrowIncentivePoolData,
|
|
2416
|
+
poolPoint,
|
|
2417
|
+
rewardCoinPrice,
|
|
2418
|
+
rewardCoinDecimal,
|
|
2419
|
+
poolCoinPrice,
|
|
2420
|
+
poolCoinDecimal
|
|
2421
|
+
);
|
|
2422
|
+
borrowIncentivePoolPoints[coinName] = {
|
|
2423
|
+
symbol,
|
|
2424
|
+
coinName: rewardCoinName,
|
|
2425
|
+
coinType: rewardCoinType,
|
|
2426
|
+
coinDecimal,
|
|
2427
|
+
coinPrice: rewardCoinPrice,
|
|
2428
|
+
points: poolPoint.points,
|
|
2429
|
+
distributedPoint: poolPoint.distributedPoint,
|
|
2430
|
+
weightedAmount: poolPoint.weightedAmount,
|
|
2431
|
+
...calculatedPoolPoint
|
|
2432
|
+
};
|
|
2433
|
+
}
|
|
2434
|
+
borrowIncentivePools[poolCoinName] = {
|
|
2435
|
+
coinName: poolCoinName,
|
|
2436
|
+
symbol: query.utils.parseSymbol(poolCoinName),
|
|
2437
|
+
coinType: poolCoinType,
|
|
2438
|
+
coinDecimal: poolCoinDecimal,
|
|
2439
|
+
coinPrice: poolCoinPrice,
|
|
2440
|
+
points: borrowIncentivePoolPoints
|
|
2308
2441
|
};
|
|
2309
2442
|
}
|
|
2310
2443
|
return borrowIncentivePools;
|
|
@@ -2323,19 +2456,13 @@ var queryBorrowIncentiveAccounts = async (query, obligationId, borrowIncentiveCo
|
|
|
2323
2456
|
const queryResult = await query.suiKit.inspectTxn(txBlock);
|
|
2324
2457
|
const borrowIncentiveAccountsQueryData = queryResult.events[0].parsedJson;
|
|
2325
2458
|
const borrowIncentiveAccounts = Object.values(
|
|
2326
|
-
borrowIncentiveAccountsQueryData.
|
|
2459
|
+
borrowIncentiveAccountsQueryData.pool_records
|
|
2327
2460
|
).reduce((accounts, accountData) => {
|
|
2328
2461
|
const parsedBorrowIncentiveAccount = parseOriginBorrowIncentiveAccountData(accountData);
|
|
2329
2462
|
const poolType = parsedBorrowIncentiveAccount.poolType;
|
|
2330
2463
|
const coinName = query.utils.parseCoinNameFromType(poolType);
|
|
2331
2464
|
if (borrowIncentiveCoinNames && borrowIncentiveCoinNames.includes(coinName)) {
|
|
2332
|
-
accounts[coinName] =
|
|
2333
|
-
poolType,
|
|
2334
|
-
amount: parsedBorrowIncentiveAccount.amount,
|
|
2335
|
-
points: parsedBorrowIncentiveAccount.points,
|
|
2336
|
-
totalPoints: parsedBorrowIncentiveAccount.totalPoints,
|
|
2337
|
-
index: parsedBorrowIncentiveAccount.index
|
|
2338
|
-
};
|
|
2465
|
+
accounts[coinName] = parsedBorrowIncentiveAccount;
|
|
2339
2466
|
}
|
|
2340
2467
|
return accounts;
|
|
2341
2468
|
}, {});
|
|
@@ -2555,9 +2682,8 @@ var getObligationAccounts = async (query, ownerAddress, indexer = false) => {
|
|
|
2555
2682
|
};
|
|
2556
2683
|
var getObligationAccount = async (query, obligationId, ownerAddress, indexer = false, market, coinPrices, coinAmounts) => {
|
|
2557
2684
|
market = market || await query.queryMarket(indexer);
|
|
2558
|
-
const
|
|
2685
|
+
const collateralAssetCoinNames = [
|
|
2559
2686
|
.../* @__PURE__ */ new Set([
|
|
2560
|
-
...Object.values(market.pools).map((pool) => pool.coinName),
|
|
2561
2687
|
...Object.values(market.collaterals).map(
|
|
2562
2688
|
(collateral) => collateral.coinName
|
|
2563
2689
|
)
|
|
@@ -2569,8 +2695,8 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
2569
2695
|
indexer
|
|
2570
2696
|
);
|
|
2571
2697
|
const borrowIncentiveAccounts = await query.getBorrowIncentiveAccounts(obligationId);
|
|
2572
|
-
coinPrices = coinPrices || await query.utils.getCoinPrices(
|
|
2573
|
-
coinAmounts = coinAmounts || await query.getCoinAmounts(
|
|
2698
|
+
coinPrices = coinPrices || await query.utils.getCoinPrices(collateralAssetCoinNames);
|
|
2699
|
+
coinAmounts = coinAmounts || await query.getCoinAmounts(collateralAssetCoinNames, ownerAddress);
|
|
2574
2700
|
const collaterals = {};
|
|
2575
2701
|
const debts = {};
|
|
2576
2702
|
const borrowIncentives = {};
|
|
@@ -2581,7 +2707,7 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
2581
2707
|
let totalBorrowedPools = 0;
|
|
2582
2708
|
let totalBorrowedValue = (0, import_bignumber3.default)(0);
|
|
2583
2709
|
let totalBorrowedValueWithWeight = (0, import_bignumber3.default)(0);
|
|
2584
|
-
for (const assetCoinName of
|
|
2710
|
+
for (const assetCoinName of collateralAssetCoinNames) {
|
|
2585
2711
|
const collateral = obligationQuery.collaterals.find((collateral2) => {
|
|
2586
2712
|
const collateralCoinName = query.utils.parseCoinNameFromType(
|
|
2587
2713
|
collateral2.type.name
|
|
@@ -2638,7 +2764,10 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
2638
2764
|
};
|
|
2639
2765
|
}
|
|
2640
2766
|
}
|
|
2641
|
-
|
|
2767
|
+
const borrowAssetCoinNames = [
|
|
2768
|
+
.../* @__PURE__ */ new Set([...Object.values(market.pools).map((pool) => pool.coinName)])
|
|
2769
|
+
];
|
|
2770
|
+
for (const assetCoinName of borrowAssetCoinNames) {
|
|
2642
2771
|
const debt = obligationQuery.debts.find((debt2) => {
|
|
2643
2772
|
const poolCoinName = query.utils.parseCoinNameFromType(
|
|
2644
2773
|
debt2.type.name
|
|
@@ -2697,34 +2826,51 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
2697
2826
|
)) {
|
|
2698
2827
|
const coinName = poolCoinName;
|
|
2699
2828
|
const borrowIncentivePool = borrowIncentivePools[coinName];
|
|
2700
|
-
let availableClaimAmount = (0, import_bignumber3.default)(0);
|
|
2701
|
-
let availableClaimCoin = (0, import_bignumber3.default)(0);
|
|
2702
2829
|
if (borrowIncentivePool) {
|
|
2703
|
-
const
|
|
2704
|
-
const
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2830
|
+
const rewards = [];
|
|
2831
|
+
for (const rewardCoinName of SUPPORT_BORROW_INCENTIVE_REWARDS) {
|
|
2832
|
+
const accountPoint = borrowIncentiveAccount.pointList[rewardCoinName];
|
|
2833
|
+
const poolPoint = borrowIncentivePool.points[rewardCoinName];
|
|
2834
|
+
if (accountPoint && poolPoint) {
|
|
2835
|
+
let availableClaimAmount = (0, import_bignumber3.default)(0);
|
|
2836
|
+
let availableClaimCoin = (0, import_bignumber3.default)(0);
|
|
2837
|
+
const accountBorrowedAmount = (0, import_bignumber3.default)(accountPoint.weightedAmount);
|
|
2838
|
+
const baseIndexRate = 1e9;
|
|
2839
|
+
const increasedPointRate = poolPoint.currentPointIndex ? (0, import_bignumber3.default)(
|
|
2840
|
+
poolPoint.currentPointIndex - accountPoint.index
|
|
2841
|
+
).dividedBy(baseIndexRate) : 1;
|
|
2842
|
+
availableClaimAmount = availableClaimAmount.plus(
|
|
2843
|
+
accountBorrowedAmount.multipliedBy(increasedPointRate).plus(accountPoint.points)
|
|
2844
|
+
);
|
|
2845
|
+
availableClaimCoin = availableClaimAmount.shiftedBy(
|
|
2846
|
+
-1 * poolPoint.coinDecimal
|
|
2847
|
+
);
|
|
2848
|
+
const weightScale = (0, import_bignumber3.default)("1000000000000");
|
|
2849
|
+
const boostValue = (0, import_bignumber3.default)(accountPoint.weightedAmount).div(
|
|
2850
|
+
(0, import_bignumber3.default)(borrowIncentiveAccount.debtAmount).multipliedBy(poolPoint.baseWeight).dividedBy(weightScale)
|
|
2851
|
+
).toNumber();
|
|
2852
|
+
if (availableClaimAmount.isGreaterThan(0)) {
|
|
2853
|
+
rewards.push({
|
|
2854
|
+
coinName: poolPoint.coinName,
|
|
2855
|
+
coinType: poolPoint.coinType,
|
|
2856
|
+
symbol: poolPoint.symbol,
|
|
2857
|
+
coinDecimal: poolPoint.coinDecimal,
|
|
2858
|
+
coinPrice: poolPoint.coinPrice,
|
|
2859
|
+
availableClaimAmount: availableClaimAmount.toNumber(),
|
|
2860
|
+
availableClaimCoin: availableClaimCoin.toNumber(),
|
|
2861
|
+
boostValue
|
|
2862
|
+
});
|
|
2863
|
+
}
|
|
2864
|
+
}
|
|
2727
2865
|
}
|
|
2866
|
+
borrowIncentives[coinName] = {
|
|
2867
|
+
coinName: borrowIncentivePool.coinName,
|
|
2868
|
+
coinType: borrowIncentivePool.coinType,
|
|
2869
|
+
symbol: borrowIncentivePool.symbol,
|
|
2870
|
+
coinDecimal: borrowIncentivePool.coinDecimal,
|
|
2871
|
+
coinPrice: borrowIncentivePool.coinPrice,
|
|
2872
|
+
rewards
|
|
2873
|
+
};
|
|
2728
2874
|
}
|
|
2729
2875
|
}
|
|
2730
2876
|
let riskLevel = totalRequiredCollateralValue.isZero() ? (0, import_bignumber3.default)(0) : totalBorrowedValueWithWeight.dividedBy(totalRequiredCollateralValue);
|
|
@@ -2852,6 +2998,70 @@ var getTotalValueLocked = async (query, indexer = false) => {
|
|
|
2852
2998
|
return tvl;
|
|
2853
2999
|
};
|
|
2854
3000
|
|
|
3001
|
+
// src/queries/vescaQuery.ts
|
|
3002
|
+
var import_bignumber4 = __toESM(require("bignumber.js"));
|
|
3003
|
+
var getVescaKeys = async (query, ownerAddress) => {
|
|
3004
|
+
const owner = ownerAddress || query.suiKit.currentAddress();
|
|
3005
|
+
const veScaPkgId = IS_VE_SCA_TEST ? "0xb220d034bdf335d77ae5bfbf6daf059c2cc7a1f719b12bfed75d1736fac038c8" : query.address.get("vesca.id");
|
|
3006
|
+
const veScaKeyType = `${veScaPkgId}::ve_sca::VeScaKey`;
|
|
3007
|
+
const keyObjectsResponse = [];
|
|
3008
|
+
let hasNextPage = false;
|
|
3009
|
+
let nextCursor = null;
|
|
3010
|
+
do {
|
|
3011
|
+
const paginatedKeyObjectsResponse = await query.suiKit.client().getOwnedObjects({
|
|
3012
|
+
owner,
|
|
3013
|
+
filter: {
|
|
3014
|
+
StructType: veScaKeyType
|
|
3015
|
+
},
|
|
3016
|
+
cursor: nextCursor
|
|
3017
|
+
});
|
|
3018
|
+
keyObjectsResponse.push(...paginatedKeyObjectsResponse.data);
|
|
3019
|
+
if (paginatedKeyObjectsResponse.hasNextPage && paginatedKeyObjectsResponse.nextCursor) {
|
|
3020
|
+
hasNextPage = true;
|
|
3021
|
+
nextCursor = paginatedKeyObjectsResponse.nextCursor;
|
|
3022
|
+
} else {
|
|
3023
|
+
hasNextPage = false;
|
|
3024
|
+
}
|
|
3025
|
+
} while (hasNextPage);
|
|
3026
|
+
const keyObjectDatas = keyObjectsResponse.map((objResponse) => objResponse.data).filter((data) => !!data);
|
|
3027
|
+
return keyObjectDatas;
|
|
3028
|
+
};
|
|
3029
|
+
var getVeScas = async (query, ownerAddress) => {
|
|
3030
|
+
const keyObjectDatas = await getVescaKeys(query, ownerAddress);
|
|
3031
|
+
const keyObjectId = keyObjectDatas.map((data) => data.objectId);
|
|
3032
|
+
const veScas = [];
|
|
3033
|
+
for (const keyId of keyObjectId) {
|
|
3034
|
+
const veSca = await getVeSca(query, keyId);
|
|
3035
|
+
if (veSca)
|
|
3036
|
+
veScas.push(veSca);
|
|
3037
|
+
}
|
|
3038
|
+
return veScas;
|
|
3039
|
+
};
|
|
3040
|
+
var getVeSca = async (query, veScaKeyId, ownerAddress) => {
|
|
3041
|
+
const tableId = IS_VE_SCA_TEST ? "0xc607241e4a679fe376d1170b2fbe07b64917bfe69100d4825241cda20039d4bd" : query.address.get(`vesca.tableId`);
|
|
3042
|
+
veScaKeyId = veScaKeyId || (await getVescaKeys(query, ownerAddress))[0].objectId;
|
|
3043
|
+
let vesca = void 0;
|
|
3044
|
+
const veScaDynamicFieldObjectResponse = await query.suiKit.client().getDynamicFieldObject({
|
|
3045
|
+
parentId: tableId,
|
|
3046
|
+
name: {
|
|
3047
|
+
type: "0x2::object::ID",
|
|
3048
|
+
value: veScaKeyId
|
|
3049
|
+
}
|
|
3050
|
+
});
|
|
3051
|
+
const veScaDynamicFieldObject = veScaDynamicFieldObjectResponse.data;
|
|
3052
|
+
if (veScaDynamicFieldObject && veScaDynamicFieldObject.content && veScaDynamicFieldObject.content.dataType === "moveObject" && "fields" in veScaDynamicFieldObject.content) {
|
|
3053
|
+
const dynamicFields = veScaDynamicFieldObject.content.fields.value.fields;
|
|
3054
|
+
vesca = {
|
|
3055
|
+
id: veScaDynamicFieldObject.objectId,
|
|
3056
|
+
keyId: veScaKeyId,
|
|
3057
|
+
lockedScaAmount: (0, import_bignumber4.default)(dynamicFields.locked_sca_amount).toNumber(),
|
|
3058
|
+
lockedScaCoin: (0, import_bignumber4.default)(dynamicFields.locked_sca_amount).shiftedBy(-9).toNumber(),
|
|
3059
|
+
unlockAt: (0, import_bignumber4.default)(dynamicFields.unlock_at).toNumber()
|
|
3060
|
+
};
|
|
3061
|
+
}
|
|
3062
|
+
return vesca;
|
|
3063
|
+
};
|
|
3064
|
+
|
|
2855
3065
|
// src/models/scallopIndexer.ts
|
|
2856
3066
|
var import_axios2 = __toESM(require("axios"));
|
|
2857
3067
|
var ScallopIndexer = class {
|
|
@@ -3694,11 +3904,43 @@ var ScallopUtils = class {
|
|
|
3694
3904
|
parseApyToApr(apy, compoundFrequency = 365) {
|
|
3695
3905
|
return ((1 + apy) ** (1 / compoundFrequency) - 1) * compoundFrequency;
|
|
3696
3906
|
}
|
|
3907
|
+
/**
|
|
3908
|
+
* Give extend lock period to get unlock at in seconds timestamp.
|
|
3909
|
+
*
|
|
3910
|
+
* @description
|
|
3911
|
+
* - When the user without remaining unlock period, If the extended unlock day is not specified,
|
|
3912
|
+
* the unlock period will be increased by one day by default.
|
|
3913
|
+
* - When the given extended day plus the user's remaining unlock period exceeds the maximum
|
|
3914
|
+
* unlock period, the maximum unlock period is used as unlock period.
|
|
3915
|
+
*
|
|
3916
|
+
* @param extendLockPeriodInDay The extend lock period in day.
|
|
3917
|
+
* @param unlockAtInSecondTimestamp The unlock timestamp from veSca object.
|
|
3918
|
+
* @return New unlock at in seconds timestamp.
|
|
3919
|
+
*/
|
|
3920
|
+
getUnlockAt(extendLockPeriodInDay, unlockAtInSecondTimestamp) {
|
|
3921
|
+
const now = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3);
|
|
3922
|
+
const remainingLockPeriod = unlockAtInSecondTimestamp ? Math.max(unlockAtInSecondTimestamp - now, 0) : 0;
|
|
3923
|
+
let newUnlockAtInSecondTimestamp = 0;
|
|
3924
|
+
if (remainingLockPeriod === 0) {
|
|
3925
|
+
const lockPeriod = (extendLockPeriodInDay ?? 1) * UNLOCK_ROUND_DURATION;
|
|
3926
|
+
newUnlockAtInSecondTimestamp = Math.min(
|
|
3927
|
+
now + lockPeriod,
|
|
3928
|
+
now + MAX_LOCK_DURATION
|
|
3929
|
+
);
|
|
3930
|
+
} else {
|
|
3931
|
+
const lockPeriod = Math.min(
|
|
3932
|
+
extendLockPeriodInDay ? extendLockPeriodInDay * UNLOCK_ROUND_DURATION + remainingLockPeriod : remainingLockPeriod,
|
|
3933
|
+
MAX_LOCK_DURATION
|
|
3934
|
+
);
|
|
3935
|
+
newUnlockAtInSecondTimestamp = now + lockPeriod;
|
|
3936
|
+
}
|
|
3937
|
+
return findClosestUnlockRound(newUnlockAtInSecondTimestamp);
|
|
3938
|
+
}
|
|
3697
3939
|
};
|
|
3698
3940
|
|
|
3699
3941
|
// src/models/scallopBuilder.ts
|
|
3700
|
-
var
|
|
3701
|
-
var
|
|
3942
|
+
var import_utils19 = require("@mysten/sui.js/utils");
|
|
3943
|
+
var import_sui_kit9 = require("@scallop-io/sui-kit");
|
|
3702
3944
|
|
|
3703
3945
|
// src/builders/coreBuilder.ts
|
|
3704
3946
|
var import_transactions = require("@mysten/sui.js/transactions");
|
|
@@ -4352,8 +4594,277 @@ var newSpoolTxBlock = (builder, initTxBlock) => {
|
|
|
4352
4594
|
|
|
4353
4595
|
// src/builders/borrowIncentiveBuilder.ts
|
|
4354
4596
|
var import_transactions3 = require("@mysten/sui.js/transactions");
|
|
4355
|
-
var
|
|
4597
|
+
var import_utils17 = require("@mysten/sui.js/utils");
|
|
4598
|
+
var import_sui_kit8 = require("@scallop-io/sui-kit");
|
|
4599
|
+
|
|
4600
|
+
// src/builders/vescaBuilder.ts
|
|
4356
4601
|
var import_sui_kit7 = require("@scallop-io/sui-kit");
|
|
4602
|
+
var requireVeSca = async (...params) => {
|
|
4603
|
+
const [builder, txBlock, veScaKey] = params;
|
|
4604
|
+
if (params.length === 3 && veScaKey && typeof veScaKey === "string") {
|
|
4605
|
+
const veSca = await getVeSca(builder.query, veScaKey);
|
|
4606
|
+
if (!veSca) {
|
|
4607
|
+
return void 0;
|
|
4608
|
+
}
|
|
4609
|
+
return veSca;
|
|
4610
|
+
}
|
|
4611
|
+
const sender = requireSender(txBlock);
|
|
4612
|
+
const veScas = await getVeScas(builder.query, sender);
|
|
4613
|
+
if (veScas.length === 0) {
|
|
4614
|
+
return void 0;
|
|
4615
|
+
}
|
|
4616
|
+
return veScas[0];
|
|
4617
|
+
};
|
|
4618
|
+
var generateNormalVeScaMethod = ({
|
|
4619
|
+
builder,
|
|
4620
|
+
txBlock
|
|
4621
|
+
}) => {
|
|
4622
|
+
const veScaIds = {
|
|
4623
|
+
pkgId: builder.address.get("vesca.id"),
|
|
4624
|
+
table: builder.address.get("vesca.table"),
|
|
4625
|
+
treasury: builder.address.get("vesca.treasury"),
|
|
4626
|
+
config: builder.address.get("vesca.config")
|
|
4627
|
+
};
|
|
4628
|
+
return {
|
|
4629
|
+
lockSca: (scaCoin, unlockAtInSecondTimestamp) => {
|
|
4630
|
+
return txBlock.moveCall(
|
|
4631
|
+
`${veScaIds.pkgId}::ve_sca::mint_ve_sca_key`,
|
|
4632
|
+
[
|
|
4633
|
+
veScaIds.config,
|
|
4634
|
+
veScaIds.table,
|
|
4635
|
+
veScaIds.treasury,
|
|
4636
|
+
scaCoin,
|
|
4637
|
+
unlockAtInSecondTimestamp,
|
|
4638
|
+
import_sui_kit7.SUI_CLOCK_OBJECT_ID
|
|
4639
|
+
],
|
|
4640
|
+
[]
|
|
4641
|
+
);
|
|
4642
|
+
},
|
|
4643
|
+
extendLockPeriod: (veScaKey, newUnlockAtInSecondTimestamp) => {
|
|
4644
|
+
txBlock.moveCall(
|
|
4645
|
+
`${veScaIds.pkgId}::ve_sca::extend_lock_period`,
|
|
4646
|
+
[
|
|
4647
|
+
veScaIds.config,
|
|
4648
|
+
veScaKey,
|
|
4649
|
+
veScaIds.table,
|
|
4650
|
+
veScaIds.treasury,
|
|
4651
|
+
newUnlockAtInSecondTimestamp,
|
|
4652
|
+
import_sui_kit7.SUI_CLOCK_OBJECT_ID
|
|
4653
|
+
],
|
|
4654
|
+
[]
|
|
4655
|
+
);
|
|
4656
|
+
},
|
|
4657
|
+
extendLockAmount: (veScaKey, scaCoin) => {
|
|
4658
|
+
txBlock.moveCall(
|
|
4659
|
+
`${veScaIds.pkgId}::ve_sca::lock_more_sca`,
|
|
4660
|
+
[
|
|
4661
|
+
veScaIds.config,
|
|
4662
|
+
veScaKey,
|
|
4663
|
+
veScaIds.table,
|
|
4664
|
+
veScaIds.treasury,
|
|
4665
|
+
scaCoin,
|
|
4666
|
+
import_sui_kit7.SUI_CLOCK_OBJECT_ID
|
|
4667
|
+
],
|
|
4668
|
+
[]
|
|
4669
|
+
);
|
|
4670
|
+
},
|
|
4671
|
+
renewExpiredVeSca: (veScaKey, scaCoin, newUnlockAtInSecondTimestamp) => {
|
|
4672
|
+
txBlock.moveCall(
|
|
4673
|
+
`${veScaIds.pkgId}::ve_sca::renew_expired_ve_sca`,
|
|
4674
|
+
[
|
|
4675
|
+
veScaIds.config,
|
|
4676
|
+
veScaKey,
|
|
4677
|
+
veScaIds.table,
|
|
4678
|
+
veScaIds.treasury,
|
|
4679
|
+
scaCoin,
|
|
4680
|
+
newUnlockAtInSecondTimestamp,
|
|
4681
|
+
import_sui_kit7.SUI_CLOCK_OBJECT_ID
|
|
4682
|
+
],
|
|
4683
|
+
[]
|
|
4684
|
+
);
|
|
4685
|
+
},
|
|
4686
|
+
redeemSca: (veScaKey) => {
|
|
4687
|
+
return txBlock.moveCall(
|
|
4688
|
+
`${veScaIds.pkgId}::ve_sca::redeem`,
|
|
4689
|
+
[
|
|
4690
|
+
veScaIds.config,
|
|
4691
|
+
veScaKey,
|
|
4692
|
+
veScaIds.table,
|
|
4693
|
+
veScaIds.treasury,
|
|
4694
|
+
import_sui_kit7.SUI_CLOCK_OBJECT_ID
|
|
4695
|
+
],
|
|
4696
|
+
[]
|
|
4697
|
+
);
|
|
4698
|
+
}
|
|
4699
|
+
};
|
|
4700
|
+
};
|
|
4701
|
+
var generateQuickVeScaMethod = ({
|
|
4702
|
+
builder,
|
|
4703
|
+
txBlock
|
|
4704
|
+
}) => {
|
|
4705
|
+
return {
|
|
4706
|
+
lockScaQuick: async (amountOrCoin, lockPeriodInDays, autoCheck = true) => {
|
|
4707
|
+
const sender = requireSender(txBlock);
|
|
4708
|
+
const veSca = await requireVeSca(builder, txBlock);
|
|
4709
|
+
let scaCoin = void 0;
|
|
4710
|
+
const transferObjects = [];
|
|
4711
|
+
if (amountOrCoin !== void 0 && typeof amountOrCoin === "number") {
|
|
4712
|
+
const coins = await builder.utils.selectCoinIds(
|
|
4713
|
+
amountOrCoin,
|
|
4714
|
+
SCA_COIN_TYPE,
|
|
4715
|
+
sender
|
|
4716
|
+
);
|
|
4717
|
+
const [takeCoin, leftCoin] = txBlock.takeAmountFromCoins(
|
|
4718
|
+
coins,
|
|
4719
|
+
amountOrCoin
|
|
4720
|
+
);
|
|
4721
|
+
scaCoin = takeCoin;
|
|
4722
|
+
transferObjects.push(leftCoin);
|
|
4723
|
+
} else {
|
|
4724
|
+
scaCoin = amountOrCoin;
|
|
4725
|
+
}
|
|
4726
|
+
const newUnlockAt = builder.utils.getUnlockAt(
|
|
4727
|
+
lockPeriodInDays,
|
|
4728
|
+
veSca?.unlockAt
|
|
4729
|
+
);
|
|
4730
|
+
if (autoCheck)
|
|
4731
|
+
checkLockSca(
|
|
4732
|
+
amountOrCoin,
|
|
4733
|
+
lockPeriodInDays,
|
|
4734
|
+
newUnlockAt,
|
|
4735
|
+
veSca?.unlockAt
|
|
4736
|
+
);
|
|
4737
|
+
console.log(
|
|
4738
|
+
new Date(newUnlockAt * 1e3).toLocaleString("en-CA", {
|
|
4739
|
+
hour12: true
|
|
4740
|
+
})
|
|
4741
|
+
);
|
|
4742
|
+
const isInitialLock = !veSca?.unlockAt;
|
|
4743
|
+
const isLockExpired = !isInitialLock && veSca.unlockAt * 1e3 <= (/* @__PURE__ */ new Date()).getTime();
|
|
4744
|
+
if (isInitialLock || isLockExpired) {
|
|
4745
|
+
if (scaCoin) {
|
|
4746
|
+
if (isInitialLock) {
|
|
4747
|
+
const veScaKey = txBlock.lockSca(scaCoin, newUnlockAt);
|
|
4748
|
+
transferObjects.push(veScaKey);
|
|
4749
|
+
} else {
|
|
4750
|
+
if (veSca.lockedScaAmount !== 0) {
|
|
4751
|
+
const unlockedSca = txBlock.redeemSca(veSca.keyId);
|
|
4752
|
+
transferObjects.push(unlockedSca);
|
|
4753
|
+
}
|
|
4754
|
+
txBlock.renewExpiredVeSca(veSca.keyId, scaCoin, newUnlockAt);
|
|
4755
|
+
}
|
|
4756
|
+
}
|
|
4757
|
+
} else {
|
|
4758
|
+
if (!!scaCoin && !!lockPeriodInDays) {
|
|
4759
|
+
txBlock.extendLockPeriod(veSca.keyId, newUnlockAt);
|
|
4760
|
+
txBlock.extendLockAmount(veSca.keyId, scaCoin);
|
|
4761
|
+
} else if (lockPeriodInDays) {
|
|
4762
|
+
txBlock.extendLockPeriod(veSca.keyId, newUnlockAt);
|
|
4763
|
+
} else if (scaCoin) {
|
|
4764
|
+
txBlock.extendLockAmount(veSca.keyId, scaCoin);
|
|
4765
|
+
}
|
|
4766
|
+
}
|
|
4767
|
+
if (transferObjects.length > 0) {
|
|
4768
|
+
txBlock.transferObjects(transferObjects, sender);
|
|
4769
|
+
}
|
|
4770
|
+
},
|
|
4771
|
+
extendLockPeriodQuick: async (lockPeriodInDays, veScaKey, autoCheck = true) => {
|
|
4772
|
+
const veSca = await requireVeSca(builder, txBlock, veScaKey);
|
|
4773
|
+
const newUnlockAt = builder.utils.getUnlockAt(lockPeriodInDays);
|
|
4774
|
+
if (autoCheck)
|
|
4775
|
+
checkExtendLockPeriod(lockPeriodInDays, newUnlockAt, veSca?.unlockAt);
|
|
4776
|
+
if (veSca) {
|
|
4777
|
+
txBlock.extendLockPeriod(veSca.keyId, newUnlockAt);
|
|
4778
|
+
}
|
|
4779
|
+
},
|
|
4780
|
+
extendLockAmountQuick: async (scaAmount, veScaKey, autoCheck = true) => {
|
|
4781
|
+
const sender = requireSender(txBlock);
|
|
4782
|
+
const veSca = await requireVeSca(builder, txBlock, veScaKey);
|
|
4783
|
+
if (autoCheck)
|
|
4784
|
+
checkExtendLockAmount(scaAmount, veSca?.unlockAt);
|
|
4785
|
+
if (veSca) {
|
|
4786
|
+
const scaCoins = await builder.utils.selectCoinIds(
|
|
4787
|
+
scaAmount,
|
|
4788
|
+
SCA_COIN_TYPE,
|
|
4789
|
+
sender
|
|
4790
|
+
);
|
|
4791
|
+
const [takeCoin, leftCoin] = txBlock.takeAmountFromCoins(
|
|
4792
|
+
scaCoins,
|
|
4793
|
+
scaAmount
|
|
4794
|
+
);
|
|
4795
|
+
txBlock.extendLockAmount(veSca.keyId, takeCoin);
|
|
4796
|
+
txBlock.transferObjects([leftCoin], sender);
|
|
4797
|
+
}
|
|
4798
|
+
},
|
|
4799
|
+
renewExpiredVeScaQuick: async (scaAmount, lockPeriodInDays, veScaKey, autoCheck = true) => {
|
|
4800
|
+
const sender = requireSender(txBlock);
|
|
4801
|
+
const veSca = await requireVeSca(builder, txBlock, veScaKey);
|
|
4802
|
+
const newUnlockAt = builder.utils.getUnlockAt(
|
|
4803
|
+
lockPeriodInDays,
|
|
4804
|
+
veSca?.unlockAt
|
|
4805
|
+
);
|
|
4806
|
+
if (autoCheck)
|
|
4807
|
+
checkRenewExpiredVeSca(scaAmount, lockPeriodInDays, veSca?.unlockAt);
|
|
4808
|
+
if (veSca) {
|
|
4809
|
+
const transferObjects = [];
|
|
4810
|
+
if (veSca.lockedScaAmount !== 0) {
|
|
4811
|
+
const unlockedSca = txBlock.redeemSca(veSca.keyId);
|
|
4812
|
+
transferObjects.push(unlockedSca);
|
|
4813
|
+
}
|
|
4814
|
+
const scaCoins = await builder.utils.selectCoinIds(
|
|
4815
|
+
scaAmount,
|
|
4816
|
+
SCA_COIN_TYPE,
|
|
4817
|
+
sender
|
|
4818
|
+
);
|
|
4819
|
+
const [takeCoin, leftCoin] = txBlock.takeAmountFromCoins(
|
|
4820
|
+
scaCoins,
|
|
4821
|
+
scaAmount
|
|
4822
|
+
);
|
|
4823
|
+
transferObjects.push(leftCoin);
|
|
4824
|
+
txBlock.renewExpiredVeSca(veSca.keyId, takeCoin, newUnlockAt);
|
|
4825
|
+
txBlock.transferObjects(transferObjects, sender);
|
|
4826
|
+
}
|
|
4827
|
+
},
|
|
4828
|
+
redeemScaQuick: async (veScaKey) => {
|
|
4829
|
+
const sender = requireSender(txBlock);
|
|
4830
|
+
const veSca = await requireVeSca(builder, txBlock, veScaKey);
|
|
4831
|
+
checkVesca(veSca?.unlockAt);
|
|
4832
|
+
if (veSca) {
|
|
4833
|
+
const sca = txBlock.redeemSca(veSca.keyId);
|
|
4834
|
+
txBlock.transferObjects([sca], sender);
|
|
4835
|
+
}
|
|
4836
|
+
}
|
|
4837
|
+
};
|
|
4838
|
+
};
|
|
4839
|
+
var newVeScaTxBlock = (builder, initTxBlock) => {
|
|
4840
|
+
const txBlock = initTxBlock instanceof import_sui_kit7.TransactionBlock ? new import_sui_kit7.SuiTxBlock(initTxBlock) : initTxBlock ? initTxBlock : new import_sui_kit7.SuiTxBlock();
|
|
4841
|
+
const normalMethod = generateNormalVeScaMethod({
|
|
4842
|
+
builder,
|
|
4843
|
+
txBlock
|
|
4844
|
+
});
|
|
4845
|
+
const normalTxBlock = new Proxy(txBlock, {
|
|
4846
|
+
get: (target, prop) => {
|
|
4847
|
+
if (prop in normalMethod) {
|
|
4848
|
+
return Reflect.get(normalMethod, prop);
|
|
4849
|
+
}
|
|
4850
|
+
return Reflect.get(target, prop);
|
|
4851
|
+
}
|
|
4852
|
+
});
|
|
4853
|
+
const quickMethod = generateQuickVeScaMethod({
|
|
4854
|
+
builder,
|
|
4855
|
+
txBlock: normalTxBlock
|
|
4856
|
+
});
|
|
4857
|
+
return new Proxy(normalTxBlock, {
|
|
4858
|
+
get: (target, prop) => {
|
|
4859
|
+
if (prop in quickMethod) {
|
|
4860
|
+
return Reflect.get(quickMethod, prop);
|
|
4861
|
+
}
|
|
4862
|
+
return Reflect.get(target, prop);
|
|
4863
|
+
}
|
|
4864
|
+
});
|
|
4865
|
+
};
|
|
4866
|
+
|
|
4867
|
+
// src/builders/borrowIncentiveBuilder.ts
|
|
4357
4868
|
var requireObligationInfo2 = async (...params) => {
|
|
4358
4869
|
const [builder, txBlock, obligationId, obligationKey] = params;
|
|
4359
4870
|
if (params.length === 4 && obligationId && obligationKey && typeof obligationId === "string") {
|
|
@@ -4374,59 +4885,115 @@ var requireObligationInfo2 = async (...params) => {
|
|
|
4374
4885
|
obligationLocked: obligations[0].locked
|
|
4375
4886
|
};
|
|
4376
4887
|
};
|
|
4888
|
+
var getBindedObligationId = async (builder, veScaKey) => {
|
|
4889
|
+
const borrowIncentivePkgId = builder.address.get("borrowIncentive.id");
|
|
4890
|
+
const incentivePoolsId = builder.address.get(
|
|
4891
|
+
"borrowIncentive.incentivePools"
|
|
4892
|
+
);
|
|
4893
|
+
const veScaPkgId = IS_VE_SCA_TEST ? "0xb220d034bdf335d77ae5bfbf6daf059c2cc7a1f719b12bfed75d1736fac038c8" : builder.address.get("vesca.id");
|
|
4894
|
+
const client = builder.suiKit.client();
|
|
4895
|
+
const incentivePoolsResponse = await client.getObject({
|
|
4896
|
+
id: incentivePoolsId,
|
|
4897
|
+
options: {
|
|
4898
|
+
showContent: true
|
|
4899
|
+
}
|
|
4900
|
+
});
|
|
4901
|
+
if (incentivePoolsResponse.data?.content?.dataType !== "moveObject")
|
|
4902
|
+
return false;
|
|
4903
|
+
const incentivePoolFields = incentivePoolsResponse.data.content.fields;
|
|
4904
|
+
const veScaBindTableId = incentivePoolFields.ve_sca_bind.fields.id.id;
|
|
4905
|
+
const keyType = `${borrowIncentivePkgId}::typed_id::TypedID<${veScaPkgId}::ve_sca::VeScaKey>`;
|
|
4906
|
+
const veScaBindTableResponse = await client.getDynamicFieldObject({
|
|
4907
|
+
parentId: veScaBindTableId,
|
|
4908
|
+
name: {
|
|
4909
|
+
type: keyType,
|
|
4910
|
+
value: veScaKey
|
|
4911
|
+
}
|
|
4912
|
+
});
|
|
4913
|
+
if (veScaBindTableResponse.data?.content?.dataType !== "moveObject")
|
|
4914
|
+
return false;
|
|
4915
|
+
const veScaBindTableFields = veScaBindTableResponse.data.content.fields;
|
|
4916
|
+
const obligationId = veScaBindTableFields.value.fields.id;
|
|
4917
|
+
return obligationId;
|
|
4918
|
+
};
|
|
4377
4919
|
var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
|
|
4378
4920
|
const borrowIncentiveIds = {
|
|
4379
|
-
borrowIncentivePkg: builder.address.get("borrowIncentive.id"),
|
|
4921
|
+
borrowIncentivePkg: IS_VE_SCA_TEST ? "0x4d5a7cefa4147b4ace0ca845b20437d6ac0d32e5f2f855171f745472c2576246" : builder.address.get("borrowIncentive.id"),
|
|
4380
4922
|
query: builder.address.get("borrowIncentive.query"),
|
|
4923
|
+
config: builder.address.get("borrowIncentive.config"),
|
|
4381
4924
|
incentivePools: builder.address.get("borrowIncentive.incentivePools"),
|
|
4382
4925
|
incentiveAccounts: builder.address.get(
|
|
4383
4926
|
"borrowIncentive.incentiveAccounts"
|
|
4384
4927
|
),
|
|
4385
4928
|
obligationAccessStore: builder.address.get("core.obligationAccessStore")
|
|
4386
4929
|
};
|
|
4930
|
+
const veScaIds = {
|
|
4931
|
+
table: builder.address.get("vesca.table"),
|
|
4932
|
+
treasury: builder.address.get("vesca.treasury"),
|
|
4933
|
+
config: builder.address.get("vesca.config")
|
|
4934
|
+
};
|
|
4387
4935
|
return {
|
|
4388
|
-
stakeObligation: (obligationId,
|
|
4389
|
-
const rewardCoinName = "sui";
|
|
4390
|
-
const rewardType = builder.utils.parseCoinType(rewardCoinName);
|
|
4936
|
+
stakeObligation: (obligationId, obligationKey) => {
|
|
4391
4937
|
txBlock.moveCall(
|
|
4392
4938
|
`${borrowIncentiveIds.borrowIncentivePkg}::user::stake`,
|
|
4393
4939
|
[
|
|
4940
|
+
borrowIncentiveIds.config,
|
|
4941
|
+
borrowIncentiveIds.incentivePools,
|
|
4942
|
+
borrowIncentiveIds.incentiveAccounts,
|
|
4943
|
+
obligationKey,
|
|
4944
|
+
obligationId,
|
|
4945
|
+
borrowIncentiveIds.obligationAccessStore,
|
|
4946
|
+
import_utils17.SUI_CLOCK_OBJECT_ID
|
|
4947
|
+
]
|
|
4948
|
+
);
|
|
4949
|
+
},
|
|
4950
|
+
stakeObligationWithVesca: (obligationId, obligationKey, veScaKey) => {
|
|
4951
|
+
txBlock.moveCall(
|
|
4952
|
+
`${borrowIncentiveIds.borrowIncentivePkg}::user::stake_with_ve_sca`,
|
|
4953
|
+
[
|
|
4954
|
+
borrowIncentiveIds.config,
|
|
4394
4955
|
borrowIncentiveIds.incentivePools,
|
|
4395
4956
|
borrowIncentiveIds.incentiveAccounts,
|
|
4396
|
-
|
|
4957
|
+
obligationKey,
|
|
4397
4958
|
obligationId,
|
|
4398
4959
|
borrowIncentiveIds.obligationAccessStore,
|
|
4399
|
-
|
|
4960
|
+
veScaIds.config,
|
|
4961
|
+
veScaIds.treasury,
|
|
4962
|
+
veScaIds.table,
|
|
4963
|
+
veScaKey,
|
|
4964
|
+
import_utils17.SUI_CLOCK_OBJECT_ID
|
|
4400
4965
|
],
|
|
4401
|
-
[
|
|
4966
|
+
[]
|
|
4402
4967
|
);
|
|
4403
4968
|
},
|
|
4404
|
-
unstakeObligation: (obligationId,
|
|
4405
|
-
const rewardCoinName = "sui";
|
|
4406
|
-
const rewardType = builder.utils.parseCoinType(rewardCoinName);
|
|
4969
|
+
unstakeObligation: (obligationId, obligationKey) => {
|
|
4407
4970
|
txBlock.moveCall(
|
|
4408
4971
|
`${borrowIncentiveIds.borrowIncentivePkg}::user::unstake`,
|
|
4409
4972
|
[
|
|
4973
|
+
borrowIncentiveIds.config,
|
|
4410
4974
|
borrowIncentiveIds.incentivePools,
|
|
4411
4975
|
borrowIncentiveIds.incentiveAccounts,
|
|
4412
|
-
|
|
4976
|
+
obligationKey,
|
|
4413
4977
|
obligationId,
|
|
4414
|
-
|
|
4415
|
-
]
|
|
4416
|
-
[rewardType]
|
|
4978
|
+
import_utils17.SUI_CLOCK_OBJECT_ID
|
|
4979
|
+
]
|
|
4417
4980
|
);
|
|
4418
4981
|
},
|
|
4419
|
-
claimBorrowIncentive: (obligationId,
|
|
4420
|
-
const
|
|
4982
|
+
claimBorrowIncentive: (obligationId, obligationKey, coinName, rewardCoinName) => {
|
|
4983
|
+
const rewardCoinNames = borrowIncentiveRewardCoins[coinName];
|
|
4984
|
+
if (rewardCoinNames.includes(rewardCoinName) === false) {
|
|
4985
|
+
throw new Error(`Invalid reward coin name ${rewardCoinName}`);
|
|
4986
|
+
}
|
|
4421
4987
|
const rewardType = builder.utils.parseCoinType(rewardCoinName);
|
|
4422
4988
|
return txBlock.moveCall(
|
|
4423
4989
|
`${borrowIncentiveIds.borrowIncentivePkg}::user::redeem_rewards`,
|
|
4424
4990
|
[
|
|
4991
|
+
borrowIncentiveIds.config,
|
|
4425
4992
|
borrowIncentiveIds.incentivePools,
|
|
4426
4993
|
borrowIncentiveIds.incentiveAccounts,
|
|
4427
|
-
|
|
4994
|
+
obligationKey,
|
|
4428
4995
|
obligationId,
|
|
4429
|
-
|
|
4996
|
+
import_utils17.SUI_CLOCK_OBJECT_ID
|
|
4430
4997
|
],
|
|
4431
4998
|
[rewardType]
|
|
4432
4999
|
);
|
|
@@ -4447,12 +5014,51 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
|
|
|
4447
5014
|
obligationKey
|
|
4448
5015
|
);
|
|
4449
5016
|
const unstakeObligationBeforeStake = !!txBlock.txBlock.blockData.transactions.find(
|
|
4450
|
-
(txn) => txn.kind === "MoveCall" && txn.target === `${
|
|
5017
|
+
(txn) => txn.kind === "MoveCall" && (txn.target === `${OLD_BORROW_INCENTIVE_PROTOCOL_ID}::user::unstake` || txn.target === (IS_VE_SCA_TEST ? `${"0x4d5a7cefa4147b4ace0ca845b20437d6ac0d32e5f2f855171f745472c2576246"}::user::unstake` : `${builder.address.get(
|
|
5018
|
+
"borrowIncentive.id"
|
|
5019
|
+
)}::user::unstake`))
|
|
4451
5020
|
);
|
|
4452
5021
|
if (!obligationLocked || unstakeObligationBeforeStake) {
|
|
4453
5022
|
txBlock.stakeObligation(obligationArg, obligationtKeyArg);
|
|
4454
5023
|
}
|
|
4455
5024
|
},
|
|
5025
|
+
stakeObligationWithVeScaQuick: async (obligation, obligationKey, veScaKey) => {
|
|
5026
|
+
const {
|
|
5027
|
+
obligationId: obligationArg,
|
|
5028
|
+
obligationKey: obligationtKeyArg,
|
|
5029
|
+
obligationLocked
|
|
5030
|
+
} = await requireObligationInfo2(
|
|
5031
|
+
builder,
|
|
5032
|
+
txBlock,
|
|
5033
|
+
obligation,
|
|
5034
|
+
obligationKey
|
|
5035
|
+
);
|
|
5036
|
+
const unstakeObligationBeforeStake = !!txBlock.txBlock.blockData.transactions.find(
|
|
5037
|
+
(txn) => txn.kind === "MoveCall" && (txn.target === `${OLD_BORROW_INCENTIVE_PROTOCOL_ID}::user::unstake` || txn.target === (IS_VE_SCA_TEST ? `${"0x4d5a7cefa4147b4ace0ca845b20437d6ac0d32e5f2f855171f745472c2576246"}::user::unstake` : `${builder.address.get(
|
|
5038
|
+
"borrowIncentive.id"
|
|
5039
|
+
)}::user::unstake`))
|
|
5040
|
+
);
|
|
5041
|
+
if (!obligationLocked || unstakeObligationBeforeStake) {
|
|
5042
|
+
const veSca = await requireVeSca(builder, txBlock, veScaKey);
|
|
5043
|
+
if (veSca) {
|
|
5044
|
+
const bindedObligationId = await getBindedObligationId(
|
|
5045
|
+
builder,
|
|
5046
|
+
veSca.keyId
|
|
5047
|
+
);
|
|
5048
|
+
if (!bindedObligationId || bindedObligationId === obligationArg) {
|
|
5049
|
+
txBlock.stakeObligationWithVesca(
|
|
5050
|
+
obligationArg,
|
|
5051
|
+
obligationtKeyArg,
|
|
5052
|
+
veSca.keyId
|
|
5053
|
+
);
|
|
5054
|
+
} else {
|
|
5055
|
+
txBlock.stakeObligation(obligationArg, obligationtKeyArg);
|
|
5056
|
+
}
|
|
5057
|
+
} else {
|
|
5058
|
+
txBlock.stakeObligation(obligationArg, obligationtKeyArg);
|
|
5059
|
+
}
|
|
5060
|
+
}
|
|
5061
|
+
},
|
|
4456
5062
|
unstakeObligationQuick: async (obligation, obligationKey) => {
|
|
4457
5063
|
const {
|
|
4458
5064
|
obligationId: obligationArg,
|
|
@@ -4468,7 +5074,7 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
|
|
|
4468
5074
|
txBlock.unstakeObligation(obligationArg, obligationtKeyArg);
|
|
4469
5075
|
}
|
|
4470
5076
|
},
|
|
4471
|
-
claimBorrowIncentiveQuick: async (coinName, obligation, obligationKey) => {
|
|
5077
|
+
claimBorrowIncentiveQuick: async (coinName, rewardCoinName, obligation, obligationKey) => {
|
|
4472
5078
|
const {
|
|
4473
5079
|
obligationId: obligationArg,
|
|
4474
5080
|
obligationKey: obligationtKeyArg
|
|
@@ -4481,13 +5087,14 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
|
|
|
4481
5087
|
return txBlock.claimBorrowIncentive(
|
|
4482
5088
|
obligationArg,
|
|
4483
5089
|
obligationtKeyArg,
|
|
4484
|
-
coinName
|
|
5090
|
+
coinName,
|
|
5091
|
+
rewardCoinName
|
|
4485
5092
|
);
|
|
4486
5093
|
}
|
|
4487
5094
|
};
|
|
4488
5095
|
};
|
|
4489
5096
|
var newBorrowIncentiveTxBlock = (builder, initTxBlock) => {
|
|
4490
|
-
const txBlock = initTxBlock instanceof import_transactions3.TransactionBlock ? new
|
|
5097
|
+
const txBlock = initTxBlock instanceof import_transactions3.TransactionBlock ? new import_sui_kit8.SuiTxBlock(initTxBlock) : initTxBlock ? initTxBlock : new import_sui_kit8.SuiTxBlock();
|
|
4491
5098
|
const normalMethod = generateBorrowIncentiveNormalMethod({
|
|
4492
5099
|
builder,
|
|
4493
5100
|
txBlock
|
|
@@ -4516,15 +5123,18 @@ var newBorrowIncentiveTxBlock = (builder, initTxBlock) => {
|
|
|
4516
5123
|
|
|
4517
5124
|
// src/builders/index.ts
|
|
4518
5125
|
var newScallopTxBlock = (builder, initTxBlock) => {
|
|
5126
|
+
const vescaTxBlock = newVeScaTxBlock(builder, initTxBlock);
|
|
4519
5127
|
const borrowIncentiveTxBlock = newBorrowIncentiveTxBlock(
|
|
4520
5128
|
builder,
|
|
4521
|
-
|
|
5129
|
+
vescaTxBlock
|
|
4522
5130
|
);
|
|
4523
5131
|
const spoolTxBlock = newSpoolTxBlock(builder, borrowIncentiveTxBlock);
|
|
4524
5132
|
const coreTxBlock = newCoreTxBlock(builder, spoolTxBlock);
|
|
4525
5133
|
return new Proxy(coreTxBlock, {
|
|
4526
5134
|
get: (target, prop) => {
|
|
4527
|
-
if (prop in
|
|
5135
|
+
if (prop in vescaTxBlock) {
|
|
5136
|
+
return Reflect.get(vescaTxBlock, prop);
|
|
5137
|
+
} else if (prop in borrowIncentiveTxBlock) {
|
|
4528
5138
|
return Reflect.get(borrowIncentiveTxBlock, prop);
|
|
4529
5139
|
} else if (prop in spoolTxBlock) {
|
|
4530
5140
|
return Reflect.get(spoolTxBlock, prop);
|
|
@@ -4538,7 +5148,7 @@ var newScallopTxBlock = (builder, initTxBlock) => {
|
|
|
4538
5148
|
var ScallopBuilder = class {
|
|
4539
5149
|
constructor(params, instance) {
|
|
4540
5150
|
this.params = params;
|
|
4541
|
-
this.suiKit = instance?.suiKit ?? new
|
|
5151
|
+
this.suiKit = instance?.suiKit ?? new import_sui_kit9.SuiKit(params);
|
|
4542
5152
|
this.address = instance?.address ?? new ScallopAddress({
|
|
4543
5153
|
id: params?.addressesId || ADDRESSES_ID,
|
|
4544
5154
|
network: params?.networkType
|
|
@@ -4552,7 +5162,7 @@ var ScallopBuilder = class {
|
|
|
4552
5162
|
address: this.address,
|
|
4553
5163
|
query: this.query
|
|
4554
5164
|
});
|
|
4555
|
-
this.walletAddress = (0,
|
|
5165
|
+
this.walletAddress = (0, import_utils19.normalizeSuiAddress)(
|
|
4556
5166
|
params?.walletAddress || this.suiKit.currentAddress()
|
|
4557
5167
|
);
|
|
4558
5168
|
this.isTestnet = params.networkType ? params.networkType === "testnet" : false;
|
|
@@ -4631,7 +5241,7 @@ var ScallopBuilder = class {
|
|
|
4631
5241
|
var ScallopClient = class {
|
|
4632
5242
|
constructor(params, instance) {
|
|
4633
5243
|
this.params = params;
|
|
4634
|
-
this.suiKit = instance?.suiKit ?? new
|
|
5244
|
+
this.suiKit = instance?.suiKit ?? new import_sui_kit10.SuiKit(params);
|
|
4635
5245
|
this.address = instance?.address ?? new ScallopAddress({
|
|
4636
5246
|
id: params?.addressesId || ADDRESSES_ID,
|
|
4637
5247
|
network: params?.networkType
|
|
@@ -4651,7 +5261,7 @@ var ScallopClient = class {
|
|
|
4651
5261
|
query: this.query,
|
|
4652
5262
|
utils: this.utils
|
|
4653
5263
|
});
|
|
4654
|
-
this.walletAddress = (0,
|
|
5264
|
+
this.walletAddress = (0, import_utils20.normalizeSuiAddress)(
|
|
4655
5265
|
params?.walletAddress || this.suiKit.currentAddress()
|
|
4656
5266
|
);
|
|
4657
5267
|
}
|
|
@@ -5024,7 +5634,7 @@ var ScallopClient = class {
|
|
|
5024
5634
|
const coins = [];
|
|
5025
5635
|
for (const stakeMarketCoin of stakeMarketCoins2) {
|
|
5026
5636
|
const stakeCoinName = this.utils.parseCoinName(stakeMarketCoinName);
|
|
5027
|
-
const coin =
|
|
5637
|
+
const coin = txBlock.withdraw(stakeMarketCoin, stakeCoinName);
|
|
5028
5638
|
coins.push(coin);
|
|
5029
5639
|
}
|
|
5030
5640
|
txBlock.transferObjects(coins, sender);
|
|
@@ -5057,17 +5667,17 @@ var ScallopClient = class {
|
|
|
5057
5667
|
/**
|
|
5058
5668
|
* stake obligaion.
|
|
5059
5669
|
*
|
|
5060
|
-
* @param
|
|
5061
|
-
* @param
|
|
5670
|
+
* @param obligationId - The obligation account object.
|
|
5671
|
+
* @param obligationKeyId - The obligation key account object.
|
|
5062
5672
|
* @param sign - Decide to directly sign the transaction or return the transaction block.
|
|
5063
5673
|
* @param walletAddress - The wallet address of the owner.
|
|
5064
5674
|
* @return Transaction block response or transaction block
|
|
5065
5675
|
*/
|
|
5066
|
-
async stakeObligation(
|
|
5676
|
+
async stakeObligation(obligationId, obligationKeyId, sign = true, walletAddress) {
|
|
5067
5677
|
const txBlock = this.builder.createTxBlock();
|
|
5068
5678
|
const sender = walletAddress || this.walletAddress;
|
|
5069
5679
|
txBlock.setSender(sender);
|
|
5070
|
-
await txBlock.stakeObligationQuick(
|
|
5680
|
+
await txBlock.stakeObligationQuick(obligationId, obligationKeyId);
|
|
5071
5681
|
if (sign) {
|
|
5072
5682
|
return await this.suiKit.signAndSendTxn(
|
|
5073
5683
|
txBlock
|
|
@@ -5079,17 +5689,17 @@ var ScallopClient = class {
|
|
|
5079
5689
|
/**
|
|
5080
5690
|
* unstake obligaion.
|
|
5081
5691
|
*
|
|
5082
|
-
* @param
|
|
5083
|
-
* @param
|
|
5692
|
+
* @param obligationId - The obligation account object.
|
|
5693
|
+
* @param obligationKeyId - The obligation key account object.
|
|
5084
5694
|
* @param sign - Decide to directly sign the transaction or return the transaction block.
|
|
5085
5695
|
* @param walletAddress - The wallet address of the owner.
|
|
5086
5696
|
* @return Transaction block response or transaction block
|
|
5087
5697
|
*/
|
|
5088
|
-
async unstakeObligation(
|
|
5698
|
+
async unstakeObligation(obligationId, obligationKeyId, sign = true, walletAddress) {
|
|
5089
5699
|
const txBlock = this.builder.createTxBlock();
|
|
5090
5700
|
const sender = walletAddress || this.walletAddress;
|
|
5091
5701
|
txBlock.setSender(sender);
|
|
5092
|
-
await txBlock.unstakeObligationQuick(
|
|
5702
|
+
await txBlock.unstakeObligationQuick(obligationId, obligationKeyId);
|
|
5093
5703
|
if (sign) {
|
|
5094
5704
|
return await this.suiKit.signAndSendTxn(
|
|
5095
5705
|
txBlock
|
|
@@ -5108,16 +5718,21 @@ var ScallopClient = class {
|
|
|
5108
5718
|
* @param walletAddress - The wallet address of the owner.
|
|
5109
5719
|
* @return Transaction block response or transaction block
|
|
5110
5720
|
*/
|
|
5111
|
-
async claimBorrowIncentive(coinName,
|
|
5721
|
+
async claimBorrowIncentive(coinName, obligationId, obligationKeyId, sign = true, walletAddress) {
|
|
5112
5722
|
const txBlock = this.builder.createTxBlock();
|
|
5113
5723
|
const sender = walletAddress || this.walletAddress;
|
|
5114
5724
|
txBlock.setSender(sender);
|
|
5115
|
-
const
|
|
5116
|
-
|
|
5117
|
-
|
|
5118
|
-
|
|
5119
|
-
|
|
5120
|
-
|
|
5725
|
+
const rewardCoins = [];
|
|
5726
|
+
for (const rewardCoinName of SUPPORT_BORROW_INCENTIVE_REWARDS) {
|
|
5727
|
+
const rewardCoin = await txBlock.claimBorrowIncentiveQuick(
|
|
5728
|
+
coinName,
|
|
5729
|
+
rewardCoinName,
|
|
5730
|
+
obligationId,
|
|
5731
|
+
obligationKeyId
|
|
5732
|
+
);
|
|
5733
|
+
rewardCoins.push(rewardCoin);
|
|
5734
|
+
}
|
|
5735
|
+
txBlock.transferObjects(rewardCoins, sender);
|
|
5121
5736
|
if (sign) {
|
|
5122
5737
|
return await this.suiKit.signAndSendTxn(
|
|
5123
5738
|
txBlock
|
|
@@ -5152,7 +5767,7 @@ var ScallopClient = class {
|
|
|
5152
5767
|
var Scallop = class {
|
|
5153
5768
|
constructor(params) {
|
|
5154
5769
|
this.params = params;
|
|
5155
|
-
this.suiKit = new
|
|
5770
|
+
this.suiKit = new import_sui_kit11.SuiKit(params);
|
|
5156
5771
|
this._address = new ScallopAddress({
|
|
5157
5772
|
id: params?.addressesId || ADDRESSES_ID,
|
|
5158
5773
|
network: params?.networkType
|
|
@@ -5240,7 +5855,14 @@ var Scallop = class {
|
|
|
5240
5855
|
ADDRESSES_ID,
|
|
5241
5856
|
API_BASE_URL,
|
|
5242
5857
|
BORROW_FEE_PROTOCOL_ID,
|
|
5858
|
+
IS_VE_SCA_TEST,
|
|
5859
|
+
MAX_LOCK_DURATION,
|
|
5860
|
+
MAX_LOCK_ROUNDS,
|
|
5861
|
+
MIN_INITIAL_LOCK_AMOUNT,
|
|
5862
|
+
MIN_TOP_UP_AMOUNT,
|
|
5863
|
+
OLD_BORROW_INCENTIVE_PROTOCOL_ID,
|
|
5243
5864
|
PROTOCOL_OBJECT_ID,
|
|
5865
|
+
SCA_COIN_TYPE,
|
|
5244
5866
|
SDK_API_BASE_URL,
|
|
5245
5867
|
SUPPORT_BORROW_INCENTIVE_POOLS,
|
|
5246
5868
|
SUPPORT_BORROW_INCENTIVE_REWARDS,
|
|
@@ -5257,6 +5879,7 @@ var Scallop = class {
|
|
|
5257
5879
|
ScallopIndexer,
|
|
5258
5880
|
ScallopQuery,
|
|
5259
5881
|
ScallopUtils,
|
|
5882
|
+
UNLOCK_ROUND_DURATION,
|
|
5260
5883
|
assetCoins,
|
|
5261
5884
|
borrowIncentiveRewardCoins,
|
|
5262
5885
|
coinDecimals,
|