@scallop-io/sui-scallop-sdk 0.44.18 → 0.44.20
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 +888 -255
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +877 -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 +226 -130
- package/src/utils/util.ts +34 -1
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"));
|
|
@@ -1018,119 +1134,120 @@ var calculateSpoolRewardPoolData = (parsedSpoolData, parsedSpoolRewardPoolData,
|
|
|
1018
1134
|
rewardPerSec: rewardPerSec.toNumber()
|
|
1019
1135
|
};
|
|
1020
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
|
+
};
|
|
1021
1156
|
var parseOriginBorrowIncentivePoolData = (originBorrowIncentivePoolData) => {
|
|
1022
1157
|
return {
|
|
1023
1158
|
poolType: (0, import_utils.normalizeStructTag)(originBorrowIncentivePoolData.pool_type.name),
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
pointPerPeriod: Number(
|
|
1027
|
-
originBorrowIncentivePoolData.distributed_point_per_period
|
|
1028
|
-
),
|
|
1029
|
-
period: Number(originBorrowIncentivePoolData.point_distribution_time),
|
|
1030
|
-
maxStake: Number(originBorrowIncentivePoolData.max_stakes),
|
|
1159
|
+
minStakes: Number(originBorrowIncentivePoolData.min_stakes),
|
|
1160
|
+
maxStakes: Number(originBorrowIncentivePoolData.max_stakes),
|
|
1031
1161
|
staked: Number(originBorrowIncentivePoolData.stakes),
|
|
1032
|
-
index: Number(originBorrowIncentivePoolData.index),
|
|
1033
1162
|
createdAt: Number(originBorrowIncentivePoolData.created_at),
|
|
1034
|
-
|
|
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
|
+
)
|
|
1035
1174
|
};
|
|
1036
1175
|
};
|
|
1037
|
-
var
|
|
1176
|
+
var calculateBorrowIncentivePoolPointData = (pasredBorrowIncentinvePoolData, parsedBorrowIncentivePoolPointData, rewardCoinPrice, rewardCoinDecimal, poolCoinPrice, poolCoinDecimal) => {
|
|
1038
1177
|
const baseIndexRate = 1e9;
|
|
1039
1178
|
const distributedPointPerSec = (0, import_bignumber.default)(
|
|
1040
|
-
|
|
1041
|
-
).dividedBy(
|
|
1042
|
-
const pointPerSec = (0, import_bignumber.default)(
|
|
1043
|
-
parsedBorrowIncentivePoolData.pointPerPeriod
|
|
1044
|
-
).dividedBy(parsedBorrowIncentivePoolData.period);
|
|
1045
|
-
const remainingPeriod = (0, import_bignumber.default)(parsedBorrowIncentivePoolData.maxPoint).minus(parsedBorrowIncentivePoolData.distributedPoint).dividedBy(pointPerSec);
|
|
1046
|
-
const startDate = parsedBorrowIncentivePoolData.createdAt;
|
|
1047
|
-
const endDate = remainingPeriod.plus(parsedBorrowIncentivePoolData.lastUpdate).integerValue().toNumber();
|
|
1179
|
+
parsedBorrowIncentivePoolPointData.distributedPointPerPeriod
|
|
1180
|
+
).dividedBy(parsedBorrowIncentivePoolPointData.period);
|
|
1048
1181
|
const timeDelta = (0, import_bignumber.default)(
|
|
1049
|
-
Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) -
|
|
1050
|
-
).dividedBy(
|
|
1051
|
-
const remainingPoints = (0, import_bignumber.default)(
|
|
1052
|
-
parsedBorrowIncentivePoolData.maxPoint
|
|
1053
|
-
).minus(parsedBorrowIncentivePoolData.distributedPoint);
|
|
1182
|
+
Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) - parsedBorrowIncentivePoolPointData.lastUpdate
|
|
1183
|
+
).dividedBy(parsedBorrowIncentivePoolPointData.period).toFixed(0);
|
|
1054
1184
|
const accumulatedPoints = import_bignumber.default.minimum(
|
|
1055
1185
|
(0, import_bignumber.default)(timeDelta).multipliedBy(
|
|
1056
|
-
|
|
1186
|
+
parsedBorrowIncentivePoolPointData.distributedPointPerPeriod
|
|
1057
1187
|
),
|
|
1058
|
-
|
|
1188
|
+
(0, import_bignumber.default)(parsedBorrowIncentivePoolPointData.points)
|
|
1059
1189
|
);
|
|
1060
|
-
const currentPointIndex = (0, import_bignumber.default)(
|
|
1061
|
-
|
|
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
|
|
1062
1194
|
);
|
|
1063
1195
|
const currentTotalDistributedPoint = (0, import_bignumber.default)(
|
|
1064
|
-
|
|
1196
|
+
parsedBorrowIncentivePoolPointData.distributedPoint
|
|
1065
1197
|
).plus(accumulatedPoints);
|
|
1066
|
-
const stakedAmount = (0, import_bignumber.default)(
|
|
1067
|
-
const stakedCoin = stakedAmount.shiftedBy(-1 *
|
|
1068
|
-
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).shiftedBy(
|
|
1211
|
+
-1 * rewardCoinDecimal
|
|
1212
|
+
);
|
|
1213
|
+
const rewardValueForYear = (0, import_bignumber.default)(rewardPerSec).multipliedBy(rateYearFactor).multipliedBy(rewardCoinPrice);
|
|
1214
|
+
const weightScale = (0, import_bignumber.default)("1000000000000");
|
|
1215
|
+
const rewardRate = rewardValueForYear.multipliedBy(
|
|
1216
|
+
(0, import_bignumber.default)(parsedBorrowIncentivePoolPointData.baseWeight).dividedBy(
|
|
1217
|
+
weightScale
|
|
1218
|
+
)
|
|
1219
|
+
).dividedBy(weightedStakedValue).isFinite() ? rewardValueForYear.multipliedBy(
|
|
1220
|
+
(0, import_bignumber.default)(parsedBorrowIncentivePoolPointData.baseWeight).dividedBy(
|
|
1221
|
+
weightScale
|
|
1222
|
+
)
|
|
1223
|
+
).dividedBy(weightedStakedValue).toNumber() : Infinity;
|
|
1069
1224
|
return {
|
|
1070
1225
|
distributedPointPerSec: distributedPointPerSec.toNumber(),
|
|
1071
1226
|
accumulatedPoints: accumulatedPoints.toNumber(),
|
|
1072
1227
|
currentPointIndex: currentPointIndex.toNumber(),
|
|
1073
1228
|
currentTotalDistributedPoint: currentTotalDistributedPoint.toNumber(),
|
|
1074
|
-
startDate: new Date(startDate * 1e3),
|
|
1075
|
-
endDate: new Date(endDate * 1e3),
|
|
1076
1229
|
stakedAmount: stakedAmount.toNumber(),
|
|
1077
1230
|
stakedCoin: stakedCoin.toNumber(),
|
|
1078
|
-
stakedValue: stakedValue.toNumber()
|
|
1231
|
+
stakedValue: stakedValue.toNumber(),
|
|
1232
|
+
baseWeight: baseWeight.toNumber(),
|
|
1233
|
+
weightedStakedAmount: weightedStakedAmount.toNumber(),
|
|
1234
|
+
weightedStakedCoin: weightedStakedCoin.toNumber(),
|
|
1235
|
+
weightedStakedValue: weightedStakedValue.toNumber(),
|
|
1236
|
+
rewardApr: rewardRate,
|
|
1237
|
+
rewardPerSec: rewardPerSec.toNumber()
|
|
1079
1238
|
};
|
|
1080
1239
|
};
|
|
1081
|
-
var
|
|
1240
|
+
var parseOriginBorrowIncentiveAccountPoolPointData = (originBorrowIncentiveAccountPoolPointData) => {
|
|
1082
1241
|
return {
|
|
1083
|
-
|
|
1084
|
-
|
|
1242
|
+
pointType: (0, import_utils.normalizeStructTag)(
|
|
1243
|
+
originBorrowIncentiveAccountPoolPointData.point_type.name
|
|
1085
1244
|
),
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
originBorrowIncentiveRewardPoolData.exchange_rate_numerator
|
|
1089
|
-
),
|
|
1090
|
-
exchangeRateDenominator: Number(
|
|
1091
|
-
originBorrowIncentiveRewardPoolData.exchange_rate_denominator
|
|
1245
|
+
weightedAmount: Number(
|
|
1246
|
+
originBorrowIncentiveAccountPoolPointData.weighted_amount
|
|
1092
1247
|
),
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
)
|
|
1096
|
-
};
|
|
1097
|
-
};
|
|
1098
|
-
var calculateBorrowIncentiveRewardPoolData = (parsedBorrowIncentivePoolData, parsedBorrowIncentiveRewardPoolData, calculatedBorrowIncentivePoolData, rewardCoinPrice, rewardCoinDecimal) => {
|
|
1099
|
-
const rateYearFactor = 365 * 24 * 60 * 60;
|
|
1100
|
-
const rewardPerSec = (0, import_bignumber.default)(
|
|
1101
|
-
calculatedBorrowIncentivePoolData.distributedPointPerSec
|
|
1102
|
-
).multipliedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateNumerator).dividedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateDenominator);
|
|
1103
|
-
const totalRewardAmount = (0, import_bignumber.default)(parsedBorrowIncentivePoolData.maxPoint).multipliedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateNumerator).dividedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateDenominator);
|
|
1104
|
-
const totalRewardCoin = totalRewardAmount.shiftedBy(-1 * rewardCoinDecimal);
|
|
1105
|
-
const totalRewardValue = totalRewardCoin.multipliedBy(rewardCoinPrice);
|
|
1106
|
-
const remaindRewardAmount = (0, import_bignumber.default)(
|
|
1107
|
-
parsedBorrowIncentiveRewardPoolData.remainingRewards
|
|
1108
|
-
);
|
|
1109
|
-
const remaindRewardCoin = remaindRewardAmount.shiftedBy(
|
|
1110
|
-
-1 * rewardCoinDecimal
|
|
1111
|
-
);
|
|
1112
|
-
const remaindRewardValue = remaindRewardCoin.multipliedBy(rewardCoinPrice);
|
|
1113
|
-
const claimedRewardAmount = (0, import_bignumber.default)(
|
|
1114
|
-
parsedBorrowIncentiveRewardPoolData.claimedRewards
|
|
1115
|
-
);
|
|
1116
|
-
const claimedRewardCoin = claimedRewardAmount.shiftedBy(
|
|
1117
|
-
-1 * rewardCoinDecimal
|
|
1118
|
-
);
|
|
1119
|
-
const claimedRewardValue = claimedRewardCoin.multipliedBy(rewardCoinPrice);
|
|
1120
|
-
const rewardValueForYear = (0, import_bignumber.default)(rewardPerSec).shiftedBy(-1 * rewardCoinDecimal).multipliedBy(rateYearFactor).multipliedBy(rewardCoinPrice);
|
|
1121
|
-
const rewardRate = rewardValueForYear.dividedBy(calculatedBorrowIncentivePoolData.stakedValue).isFinite() ? rewardValueForYear.dividedBy(calculatedBorrowIncentivePoolData.stakedValue).toNumber() : Infinity;
|
|
1122
|
-
return {
|
|
1123
|
-
rewardApr: rewardRate,
|
|
1124
|
-
totalRewardAmount: totalRewardAmount.toNumber(),
|
|
1125
|
-
totalRewardCoin: totalRewardCoin.toNumber(),
|
|
1126
|
-
totalRewardValue: totalRewardValue.toNumber(),
|
|
1127
|
-
remaindRewardAmount: remaindRewardAmount.toNumber(),
|
|
1128
|
-
remaindRewardCoin: remaindRewardCoin.toNumber(),
|
|
1129
|
-
remaindRewardValue: remaindRewardValue.toNumber(),
|
|
1130
|
-
claimedRewardAmount: claimedRewardAmount.toNumber(),
|
|
1131
|
-
claimedRewardCoin: claimedRewardCoin.toNumber(),
|
|
1132
|
-
claimedRewardValue: claimedRewardValue.toNumber(),
|
|
1133
|
-
rewardPerSec: rewardPerSec.toNumber()
|
|
1248
|
+
points: Number(originBorrowIncentiveAccountPoolPointData.points),
|
|
1249
|
+
totalPoints: Number(originBorrowIncentiveAccountPoolPointData.total_points),
|
|
1250
|
+
index: Number(originBorrowIncentiveAccountPoolPointData.index)
|
|
1134
1251
|
};
|
|
1135
1252
|
};
|
|
1136
1253
|
var parseOriginBorrowIncentiveAccountData = (originBorrowIncentiveAccountData) => {
|
|
@@ -1138,10 +1255,18 @@ var parseOriginBorrowIncentiveAccountData = (originBorrowIncentiveAccountData) =
|
|
|
1138
1255
|
poolType: (0, import_utils.normalizeStructTag)(
|
|
1139
1256
|
originBorrowIncentiveAccountData.pool_type.name
|
|
1140
1257
|
),
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1258
|
+
debtAmount: Number(originBorrowIncentiveAccountData.debt_amount),
|
|
1259
|
+
pointList: originBorrowIncentiveAccountData.points_list.reduce(
|
|
1260
|
+
(acc, point) => {
|
|
1261
|
+
const parsed = parseOriginBorrowIncentiveAccountPoolPointData(point);
|
|
1262
|
+
const name = (0, import_utils.parseStructTag)(
|
|
1263
|
+
parsed.pointType
|
|
1264
|
+
).name.toLowerCase();
|
|
1265
|
+
acc[name] = parsed;
|
|
1266
|
+
return acc;
|
|
1267
|
+
},
|
|
1268
|
+
{}
|
|
1269
|
+
)
|
|
1145
1270
|
};
|
|
1146
1271
|
};
|
|
1147
1272
|
var minBigNumber = (...args) => {
|
|
@@ -1169,7 +1294,8 @@ var isMarketCoin = (coinName) => {
|
|
|
1169
1294
|
.../* @__PURE__ */ new Set([
|
|
1170
1295
|
...SUPPORT_POOLS,
|
|
1171
1296
|
...SUPPORT_COLLATERALS,
|
|
1172
|
-
...SUPPORT_SPOOLS_REWARDS
|
|
1297
|
+
...SUPPORT_SPOOLS_REWARDS,
|
|
1298
|
+
...SUPPORT_BORROW_INCENTIVE_REWARDS
|
|
1173
1299
|
])
|
|
1174
1300
|
].includes(assetCoinName);
|
|
1175
1301
|
};
|
|
@@ -1187,7 +1313,12 @@ var parseAssetSymbol = (coinName) => {
|
|
|
1187
1313
|
};
|
|
1188
1314
|
var parseDataFromPythPriceFeed = (feed, address) => {
|
|
1189
1315
|
const assetCoinNames = [
|
|
1190
|
-
.../* @__PURE__ */ new Set([
|
|
1316
|
+
.../* @__PURE__ */ new Set([
|
|
1317
|
+
...SUPPORT_POOLS,
|
|
1318
|
+
...SUPPORT_COLLATERALS,
|
|
1319
|
+
...SUPPORT_SPOOLS_REWARDS,
|
|
1320
|
+
...SUPPORT_BORROW_INCENTIVE_REWARDS
|
|
1321
|
+
])
|
|
1191
1322
|
];
|
|
1192
1323
|
const assetCoinName = assetCoinNames.find((assetCoinName2) => {
|
|
1193
1324
|
return address.get(`core.coins.${assetCoinName2}.oracle.pyth.feed`) === feed.id;
|
|
@@ -1203,6 +1334,19 @@ var parseDataFromPythPriceFeed = (feed, address) => {
|
|
|
1203
1334
|
throw new Error("Invalid feed id");
|
|
1204
1335
|
}
|
|
1205
1336
|
};
|
|
1337
|
+
var findClosestUnlockRound = (unlockAtInSecondTimestamp) => {
|
|
1338
|
+
const unlockDate = new Date(unlockAtInSecondTimestamp * 1e3);
|
|
1339
|
+
const closestTwelveAM = new Date(unlockAtInSecondTimestamp * 1e3);
|
|
1340
|
+
closestTwelveAM.setUTCHours(0, 0, 0, 0);
|
|
1341
|
+
if (unlockDate.getUTCHours() >= 0) {
|
|
1342
|
+
closestTwelveAM.setUTCDate(closestTwelveAM.getUTCDate() + 1);
|
|
1343
|
+
}
|
|
1344
|
+
const now = (/* @__PURE__ */ new Date()).getTime();
|
|
1345
|
+
if (closestTwelveAM.getTime() - now > MAX_LOCK_DURATION * 1e3) {
|
|
1346
|
+
closestTwelveAM.setUTCDate(closestTwelveAM.getUTCDate() - 1);
|
|
1347
|
+
}
|
|
1348
|
+
return Math.floor(closestTwelveAM.getTime() / 1e3);
|
|
1349
|
+
};
|
|
1206
1350
|
|
|
1207
1351
|
// src/queries/coreQuery.ts
|
|
1208
1352
|
var queryMarket = async (query, indexer = false) => {
|
|
@@ -1391,7 +1535,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
|
|
|
1391
1535
|
const fields = marketObject.content.fields;
|
|
1392
1536
|
const coinType = query.utils.parseCoinType(poolCoinName);
|
|
1393
1537
|
const balanceSheetParentId = fields.vault.fields.balance_sheets.fields.table.fields.id.id;
|
|
1394
|
-
const
|
|
1538
|
+
const balanceSheetDynamicFieldObjectResponse = await query.suiKit.client().getDynamicFieldObject({
|
|
1395
1539
|
parentId: balanceSheetParentId,
|
|
1396
1540
|
name: {
|
|
1397
1541
|
type: "0x1::type_name::TypeName",
|
|
@@ -1400,9 +1544,9 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
|
|
|
1400
1544
|
}
|
|
1401
1545
|
}
|
|
1402
1546
|
});
|
|
1403
|
-
const
|
|
1404
|
-
if (
|
|
1405
|
-
const dynamicFields =
|
|
1547
|
+
const balanceSheetDynamicFieldObject = balanceSheetDynamicFieldObjectResponse.data;
|
|
1548
|
+
if (balanceSheetDynamicFieldObject && balanceSheetDynamicFieldObject.content && "fields" in balanceSheetDynamicFieldObject.content) {
|
|
1549
|
+
const dynamicFields = balanceSheetDynamicFieldObject.content.fields;
|
|
1406
1550
|
balanceSheet = dynamicFields.value.fields;
|
|
1407
1551
|
}
|
|
1408
1552
|
const borrowIndexParentId = fields.borrow_dynamics.fields.table.fields.id.id;
|
|
@@ -1562,7 +1706,7 @@ var getMarketCollateral = async (query, collateralCoinName, indexer = false, mar
|
|
|
1562
1706
|
const fields = marketObject.content.fields;
|
|
1563
1707
|
const coinType = query.utils.parseCoinType(collateralCoinName);
|
|
1564
1708
|
const riskModelParentId = fields.risk_models.fields.table.fields.id.id;
|
|
1565
|
-
const
|
|
1709
|
+
const riskModelDynamicFieldObjectResponse = await query.suiKit.client().getDynamicFieldObject({
|
|
1566
1710
|
parentId: riskModelParentId,
|
|
1567
1711
|
name: {
|
|
1568
1712
|
type: "0x1::type_name::TypeName",
|
|
@@ -1571,9 +1715,9 @@ var getMarketCollateral = async (query, collateralCoinName, indexer = false, mar
|
|
|
1571
1715
|
}
|
|
1572
1716
|
}
|
|
1573
1717
|
});
|
|
1574
|
-
const
|
|
1575
|
-
if (
|
|
1576
|
-
const dynamicFields =
|
|
1718
|
+
const riskModelDynamicFieldObject = riskModelDynamicFieldObjectResponse.data;
|
|
1719
|
+
if (riskModelDynamicFieldObject && riskModelDynamicFieldObject.content && "fields" in riskModelDynamicFieldObject.content) {
|
|
1720
|
+
const dynamicFields = riskModelDynamicFieldObject.content.fields;
|
|
1577
1721
|
riskModel = dynamicFields.value.fields;
|
|
1578
1722
|
}
|
|
1579
1723
|
const collateralStatParentId = fields.collateral_stats.fields.table.fields.id.id;
|
|
@@ -2243,71 +2387,70 @@ var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames, indexer
|
|
|
2243
2387
|
const incentivePoolsId = query.address.get("borrowIncentive.incentivePools");
|
|
2244
2388
|
const txBlock = new import_sui_kit2.SuiTxBlock();
|
|
2245
2389
|
const queryTarget = `${queryPkgId}::incentive_pools_query::incentive_pools_data`;
|
|
2246
|
-
txBlock.moveCall(queryTarget, [incentivePoolsId]
|
|
2390
|
+
txBlock.moveCall(queryTarget, [incentivePoolsId]);
|
|
2247
2391
|
const queryResult = await query.suiKit.inspectTxn(txBlock);
|
|
2248
2392
|
const borrowIncentivePoolsQueryData = queryResult.events[0].parsedJson;
|
|
2249
|
-
const parsedBorrowIncentiveRewardPoolData = parseOriginBorrowIncentiveRewardPoolData(
|
|
2250
|
-
borrowIncentivePoolsQueryData.reward_pool
|
|
2251
|
-
);
|
|
2252
|
-
const rewardCoinType = parsedBorrowIncentiveRewardPoolData.rewardType;
|
|
2253
|
-
const rewardCoinName = query.utils.parseCoinNameFromType(rewardCoinType);
|
|
2254
|
-
const coinPrices = await query.utils.getCoinPrices(
|
|
2255
|
-
[.../* @__PURE__ */ new Set([...borrowIncentiveCoinNames, rewardCoinName])]
|
|
2256
|
-
);
|
|
2257
2393
|
const borrowIncentivePools = {};
|
|
2258
2394
|
if (indexer) {
|
|
2259
|
-
const borrowIncentivePoolsIndexer = await query.indexer.getBorrowIncentivePools();
|
|
2260
|
-
for (const borrowIncentivePool of Object.values(
|
|
2261
|
-
borrowIncentivePoolsIndexer
|
|
2262
|
-
)) {
|
|
2263
|
-
if (!borrowIncentiveCoinNames.includes(borrowIncentivePool.coinName))
|
|
2264
|
-
continue;
|
|
2265
|
-
borrowIncentivePool.coinPrice = coinPrices[borrowIncentivePool.coinName] || borrowIncentivePool.coinPrice;
|
|
2266
|
-
borrowIncentivePool.rewardCoinPrice = coinPrices[rewardCoinName] || borrowIncentivePool.rewardCoinPrice;
|
|
2267
|
-
borrowIncentivePools[borrowIncentivePool.coinName] = borrowIncentivePool;
|
|
2268
|
-
}
|
|
2269
|
-
return borrowIncentivePools;
|
|
2270
2395
|
}
|
|
2271
2396
|
for (const pool of borrowIncentivePoolsQueryData.incentive_pools) {
|
|
2272
|
-
const
|
|
2273
|
-
const coinName = query.utils.parseCoinNameFromType(coinType);
|
|
2274
|
-
const rewardCoinName2 = query.utils.parseCoinNameFromType(rewardCoinType);
|
|
2275
|
-
if (!borrowIncentiveCoinNames.includes(coinName)) {
|
|
2276
|
-
continue;
|
|
2277
|
-
}
|
|
2397
|
+
const borrowIncentivePoolPoints = {};
|
|
2278
2398
|
const parsedBorrowIncentivePoolData = parseOriginBorrowIncentivePoolData(pool);
|
|
2279
|
-
const
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2399
|
+
const coinPrices = await query.utils.getCoinPrices(
|
|
2400
|
+
[
|
|
2401
|
+
.../* @__PURE__ */ new Set([
|
|
2402
|
+
...borrowIncentiveCoinNames,
|
|
2403
|
+
...SUPPORT_BORROW_INCENTIVE_REWARDS
|
|
2404
|
+
])
|
|
2405
|
+
]
|
|
2285
2406
|
);
|
|
2286
|
-
const
|
|
2287
|
-
const
|
|
2288
|
-
|
|
2289
|
-
parsedBorrowIncentivePoolData,
|
|
2290
|
-
parsedBorrowIncentiveRewardPoolData,
|
|
2291
|
-
calculatedBorrowIncentivePoolData,
|
|
2292
|
-
rewardCoinPrice,
|
|
2293
|
-
rewardCoinDecimal
|
|
2407
|
+
const poolCoinType = (0, import_utils6.normalizeStructTag)(pool.pool_type.name);
|
|
2408
|
+
const poolCoinName = query.utils.parseCoinNameFromType(
|
|
2409
|
+
poolCoinType
|
|
2294
2410
|
);
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2411
|
+
const poolCoinPrice = coinPrices?.[poolCoinName] ?? 0;
|
|
2412
|
+
const poolCoinDecimal = query.utils.getCoinDecimal(poolCoinName);
|
|
2413
|
+
if (!borrowIncentiveCoinNames.includes(poolCoinName)) {
|
|
2414
|
+
continue;
|
|
2415
|
+
}
|
|
2416
|
+
for (const [coinName, poolPoint] of Object.entries(
|
|
2417
|
+
parsedBorrowIncentivePoolData.poolPoints
|
|
2418
|
+
)) {
|
|
2419
|
+
const rewardCoinType = (0, import_utils6.normalizeStructTag)(poolPoint.pointType);
|
|
2420
|
+
const rewardCoinName = query.utils.parseCoinNameFromType(
|
|
2421
|
+
rewardCoinType
|
|
2422
|
+
);
|
|
2423
|
+
const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
|
|
2424
|
+
const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
2425
|
+
const symbol = query.utils.parseSymbol(rewardCoinName);
|
|
2426
|
+
const coinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
2427
|
+
const calculatedPoolPoint = calculateBorrowIncentivePoolPointData(
|
|
2428
|
+
parsedBorrowIncentivePoolData,
|
|
2429
|
+
poolPoint,
|
|
2430
|
+
rewardCoinPrice,
|
|
2431
|
+
rewardCoinDecimal,
|
|
2432
|
+
poolCoinPrice,
|
|
2433
|
+
poolCoinDecimal
|
|
2434
|
+
);
|
|
2435
|
+
borrowIncentivePoolPoints[coinName] = {
|
|
2436
|
+
symbol,
|
|
2437
|
+
coinName: rewardCoinName,
|
|
2438
|
+
coinType: rewardCoinType,
|
|
2439
|
+
coinDecimal,
|
|
2440
|
+
coinPrice: rewardCoinPrice,
|
|
2441
|
+
points: poolPoint.points,
|
|
2442
|
+
distributedPoint: poolPoint.distributedPoint,
|
|
2443
|
+
weightedAmount: poolPoint.weightedAmount,
|
|
2444
|
+
...calculatedPoolPoint
|
|
2445
|
+
};
|
|
2446
|
+
}
|
|
2447
|
+
borrowIncentivePools[poolCoinName] = {
|
|
2448
|
+
coinName: poolCoinName,
|
|
2449
|
+
symbol: query.utils.parseSymbol(poolCoinName),
|
|
2450
|
+
coinType: poolCoinType,
|
|
2451
|
+
coinDecimal: poolCoinDecimal,
|
|
2452
|
+
coinPrice: poolCoinPrice,
|
|
2453
|
+
points: borrowIncentivePoolPoints
|
|
2311
2454
|
};
|
|
2312
2455
|
}
|
|
2313
2456
|
return borrowIncentivePools;
|
|
@@ -2326,19 +2469,13 @@ var queryBorrowIncentiveAccounts = async (query, obligationId, borrowIncentiveCo
|
|
|
2326
2469
|
const queryResult = await query.suiKit.inspectTxn(txBlock);
|
|
2327
2470
|
const borrowIncentiveAccountsQueryData = queryResult.events[0].parsedJson;
|
|
2328
2471
|
const borrowIncentiveAccounts = Object.values(
|
|
2329
|
-
borrowIncentiveAccountsQueryData.
|
|
2472
|
+
borrowIncentiveAccountsQueryData.pool_records
|
|
2330
2473
|
).reduce((accounts, accountData) => {
|
|
2331
2474
|
const parsedBorrowIncentiveAccount = parseOriginBorrowIncentiveAccountData(accountData);
|
|
2332
2475
|
const poolType = parsedBorrowIncentiveAccount.poolType;
|
|
2333
2476
|
const coinName = query.utils.parseCoinNameFromType(poolType);
|
|
2334
2477
|
if (borrowIncentiveCoinNames && borrowIncentiveCoinNames.includes(coinName)) {
|
|
2335
|
-
accounts[coinName] =
|
|
2336
|
-
poolType,
|
|
2337
|
-
amount: parsedBorrowIncentiveAccount.amount,
|
|
2338
|
-
points: parsedBorrowIncentiveAccount.points,
|
|
2339
|
-
totalPoints: parsedBorrowIncentiveAccount.totalPoints,
|
|
2340
|
-
index: parsedBorrowIncentiveAccount.index
|
|
2341
|
-
};
|
|
2478
|
+
accounts[coinName] = parsedBorrowIncentiveAccount;
|
|
2342
2479
|
}
|
|
2343
2480
|
return accounts;
|
|
2344
2481
|
}, {});
|
|
@@ -2558,9 +2695,8 @@ var getObligationAccounts = async (query, ownerAddress, indexer = false) => {
|
|
|
2558
2695
|
};
|
|
2559
2696
|
var getObligationAccount = async (query, obligationId, ownerAddress, indexer = false, market, coinPrices, coinAmounts) => {
|
|
2560
2697
|
market = market || await query.queryMarket(indexer);
|
|
2561
|
-
const
|
|
2698
|
+
const collateralAssetCoinNames = [
|
|
2562
2699
|
.../* @__PURE__ */ new Set([
|
|
2563
|
-
...Object.values(market.pools).map((pool) => pool.coinName),
|
|
2564
2700
|
...Object.values(market.collaterals).map(
|
|
2565
2701
|
(collateral) => collateral.coinName
|
|
2566
2702
|
)
|
|
@@ -2572,8 +2708,8 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
2572
2708
|
indexer
|
|
2573
2709
|
);
|
|
2574
2710
|
const borrowIncentiveAccounts = await query.getBorrowIncentiveAccounts(obligationId);
|
|
2575
|
-
coinPrices = coinPrices || await query.utils.getCoinPrices(
|
|
2576
|
-
coinAmounts = coinAmounts || await query.getCoinAmounts(
|
|
2711
|
+
coinPrices = coinPrices || await query.utils.getCoinPrices(collateralAssetCoinNames);
|
|
2712
|
+
coinAmounts = coinAmounts || await query.getCoinAmounts(collateralAssetCoinNames, ownerAddress);
|
|
2577
2713
|
const collaterals = {};
|
|
2578
2714
|
const debts = {};
|
|
2579
2715
|
const borrowIncentives = {};
|
|
@@ -2584,7 +2720,7 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
2584
2720
|
let totalBorrowedPools = 0;
|
|
2585
2721
|
let totalBorrowedValue = (0, import_bignumber3.default)(0);
|
|
2586
2722
|
let totalBorrowedValueWithWeight = (0, import_bignumber3.default)(0);
|
|
2587
|
-
for (const assetCoinName of
|
|
2723
|
+
for (const assetCoinName of collateralAssetCoinNames) {
|
|
2588
2724
|
const collateral = obligationQuery.collaterals.find((collateral2) => {
|
|
2589
2725
|
const collateralCoinName = query.utils.parseCoinNameFromType(
|
|
2590
2726
|
collateral2.type.name
|
|
@@ -2641,7 +2777,10 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
2641
2777
|
};
|
|
2642
2778
|
}
|
|
2643
2779
|
}
|
|
2644
|
-
|
|
2780
|
+
const borrowAssetCoinNames = [
|
|
2781
|
+
.../* @__PURE__ */ new Set([...Object.values(market.pools).map((pool) => pool.coinName)])
|
|
2782
|
+
];
|
|
2783
|
+
for (const assetCoinName of borrowAssetCoinNames) {
|
|
2645
2784
|
const debt = obligationQuery.debts.find((debt2) => {
|
|
2646
2785
|
const poolCoinName = query.utils.parseCoinNameFromType(
|
|
2647
2786
|
debt2.type.name
|
|
@@ -2700,34 +2839,51 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
2700
2839
|
)) {
|
|
2701
2840
|
const coinName = poolCoinName;
|
|
2702
2841
|
const borrowIncentivePool = borrowIncentivePools[coinName];
|
|
2703
|
-
let availableClaimAmount = (0, import_bignumber3.default)(0);
|
|
2704
|
-
let availableClaimCoin = (0, import_bignumber3.default)(0);
|
|
2705
2842
|
if (borrowIncentivePool) {
|
|
2706
|
-
const
|
|
2707
|
-
const
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2843
|
+
const rewards = [];
|
|
2844
|
+
for (const rewardCoinName of SUPPORT_BORROW_INCENTIVE_REWARDS) {
|
|
2845
|
+
const accountPoint = borrowIncentiveAccount.pointList[rewardCoinName];
|
|
2846
|
+
const poolPoint = borrowIncentivePool.points[rewardCoinName];
|
|
2847
|
+
if (accountPoint && poolPoint) {
|
|
2848
|
+
let availableClaimAmount = (0, import_bignumber3.default)(0);
|
|
2849
|
+
let availableClaimCoin = (0, import_bignumber3.default)(0);
|
|
2850
|
+
const accountBorrowedAmount = (0, import_bignumber3.default)(accountPoint.weightedAmount);
|
|
2851
|
+
const baseIndexRate = 1e9;
|
|
2852
|
+
const increasedPointRate = poolPoint.currentPointIndex ? (0, import_bignumber3.default)(
|
|
2853
|
+
poolPoint.currentPointIndex - accountPoint.index
|
|
2854
|
+
).dividedBy(baseIndexRate) : 1;
|
|
2855
|
+
availableClaimAmount = availableClaimAmount.plus(
|
|
2856
|
+
accountBorrowedAmount.multipliedBy(increasedPointRate).plus(accountPoint.points)
|
|
2857
|
+
);
|
|
2858
|
+
availableClaimCoin = availableClaimAmount.shiftedBy(
|
|
2859
|
+
-1 * poolPoint.coinDecimal
|
|
2860
|
+
);
|
|
2861
|
+
const weightScale = (0, import_bignumber3.default)("1000000000000");
|
|
2862
|
+
const boostValue = (0, import_bignumber3.default)(accountPoint.weightedAmount).div(
|
|
2863
|
+
(0, import_bignumber3.default)(borrowIncentiveAccount.debtAmount).multipliedBy(poolPoint.baseWeight).dividedBy(weightScale)
|
|
2864
|
+
).toNumber();
|
|
2865
|
+
if (availableClaimAmount.isGreaterThan(0)) {
|
|
2866
|
+
rewards.push({
|
|
2867
|
+
coinName: poolPoint.coinName,
|
|
2868
|
+
coinType: poolPoint.coinType,
|
|
2869
|
+
symbol: poolPoint.symbol,
|
|
2870
|
+
coinDecimal: poolPoint.coinDecimal,
|
|
2871
|
+
coinPrice: poolPoint.coinPrice,
|
|
2872
|
+
availableClaimAmount: availableClaimAmount.toNumber(),
|
|
2873
|
+
availableClaimCoin: availableClaimCoin.toNumber(),
|
|
2874
|
+
boostValue
|
|
2875
|
+
});
|
|
2876
|
+
}
|
|
2877
|
+
}
|
|
2730
2878
|
}
|
|
2879
|
+
borrowIncentives[coinName] = {
|
|
2880
|
+
coinName: borrowIncentivePool.coinName,
|
|
2881
|
+
coinType: borrowIncentivePool.coinType,
|
|
2882
|
+
symbol: borrowIncentivePool.symbol,
|
|
2883
|
+
coinDecimal: borrowIncentivePool.coinDecimal,
|
|
2884
|
+
coinPrice: borrowIncentivePool.coinPrice,
|
|
2885
|
+
rewards
|
|
2886
|
+
};
|
|
2731
2887
|
}
|
|
2732
2888
|
}
|
|
2733
2889
|
let riskLevel = totalRequiredCollateralValue.isZero() ? (0, import_bignumber3.default)(0) : totalBorrowedValueWithWeight.dividedBy(totalRequiredCollateralValue);
|
|
@@ -2855,6 +3011,70 @@ var getTotalValueLocked = async (query, indexer = false) => {
|
|
|
2855
3011
|
return tvl;
|
|
2856
3012
|
};
|
|
2857
3013
|
|
|
3014
|
+
// src/queries/vescaQuery.ts
|
|
3015
|
+
var import_bignumber4 = __toESM(require("bignumber.js"));
|
|
3016
|
+
var getVescaKeys = async (query, ownerAddress) => {
|
|
3017
|
+
const owner = ownerAddress || query.suiKit.currentAddress();
|
|
3018
|
+
const veScaPkgId = IS_VE_SCA_TEST ? "0xb220d034bdf335d77ae5bfbf6daf059c2cc7a1f719b12bfed75d1736fac038c8" : query.address.get("vesca.id");
|
|
3019
|
+
const veScaKeyType = `${veScaPkgId}::ve_sca::VeScaKey`;
|
|
3020
|
+
const keyObjectsResponse = [];
|
|
3021
|
+
let hasNextPage = false;
|
|
3022
|
+
let nextCursor = null;
|
|
3023
|
+
do {
|
|
3024
|
+
const paginatedKeyObjectsResponse = await query.suiKit.client().getOwnedObjects({
|
|
3025
|
+
owner,
|
|
3026
|
+
filter: {
|
|
3027
|
+
StructType: veScaKeyType
|
|
3028
|
+
},
|
|
3029
|
+
cursor: nextCursor
|
|
3030
|
+
});
|
|
3031
|
+
keyObjectsResponse.push(...paginatedKeyObjectsResponse.data);
|
|
3032
|
+
if (paginatedKeyObjectsResponse.hasNextPage && paginatedKeyObjectsResponse.nextCursor) {
|
|
3033
|
+
hasNextPage = true;
|
|
3034
|
+
nextCursor = paginatedKeyObjectsResponse.nextCursor;
|
|
3035
|
+
} else {
|
|
3036
|
+
hasNextPage = false;
|
|
3037
|
+
}
|
|
3038
|
+
} while (hasNextPage);
|
|
3039
|
+
const keyObjectDatas = keyObjectsResponse.map((objResponse) => objResponse.data).filter((data) => !!data);
|
|
3040
|
+
return keyObjectDatas;
|
|
3041
|
+
};
|
|
3042
|
+
var getVeScas = async (query, ownerAddress) => {
|
|
3043
|
+
const keyObjectDatas = await getVescaKeys(query, ownerAddress);
|
|
3044
|
+
const keyObjectId = keyObjectDatas.map((data) => data.objectId);
|
|
3045
|
+
const veScas = [];
|
|
3046
|
+
for (const keyId of keyObjectId) {
|
|
3047
|
+
const veSca = await getVeSca(query, keyId);
|
|
3048
|
+
if (veSca)
|
|
3049
|
+
veScas.push(veSca);
|
|
3050
|
+
}
|
|
3051
|
+
return veScas;
|
|
3052
|
+
};
|
|
3053
|
+
var getVeSca = async (query, veScaKeyId, ownerAddress) => {
|
|
3054
|
+
const tableId = IS_VE_SCA_TEST ? "0xc607241e4a679fe376d1170b2fbe07b64917bfe69100d4825241cda20039d4bd" : query.address.get(`vesca.tableId`);
|
|
3055
|
+
veScaKeyId = veScaKeyId || (await getVescaKeys(query, ownerAddress))[0].objectId;
|
|
3056
|
+
let vesca = void 0;
|
|
3057
|
+
const veScaDynamicFieldObjectResponse = await query.suiKit.client().getDynamicFieldObject({
|
|
3058
|
+
parentId: tableId,
|
|
3059
|
+
name: {
|
|
3060
|
+
type: "0x2::object::ID",
|
|
3061
|
+
value: veScaKeyId
|
|
3062
|
+
}
|
|
3063
|
+
});
|
|
3064
|
+
const veScaDynamicFieldObject = veScaDynamicFieldObjectResponse.data;
|
|
3065
|
+
if (veScaDynamicFieldObject && veScaDynamicFieldObject.content && veScaDynamicFieldObject.content.dataType === "moveObject" && "fields" in veScaDynamicFieldObject.content) {
|
|
3066
|
+
const dynamicFields = veScaDynamicFieldObject.content.fields.value.fields;
|
|
3067
|
+
vesca = {
|
|
3068
|
+
id: veScaDynamicFieldObject.objectId,
|
|
3069
|
+
keyId: veScaKeyId,
|
|
3070
|
+
lockedScaAmount: (0, import_bignumber4.default)(dynamicFields.locked_sca_amount).toNumber(),
|
|
3071
|
+
lockedScaCoin: (0, import_bignumber4.default)(dynamicFields.locked_sca_amount).shiftedBy(-9).toNumber(),
|
|
3072
|
+
unlockAt: (0, import_bignumber4.default)(dynamicFields.unlock_at).toNumber()
|
|
3073
|
+
};
|
|
3074
|
+
}
|
|
3075
|
+
return vesca;
|
|
3076
|
+
};
|
|
3077
|
+
|
|
2858
3078
|
// src/models/scallopIndexer.ts
|
|
2859
3079
|
var import_axios2 = __toESM(require("axios"));
|
|
2860
3080
|
var ScallopIndexer = class {
|
|
@@ -3697,11 +3917,43 @@ var ScallopUtils = class {
|
|
|
3697
3917
|
parseApyToApr(apy, compoundFrequency = 365) {
|
|
3698
3918
|
return ((1 + apy) ** (1 / compoundFrequency) - 1) * compoundFrequency;
|
|
3699
3919
|
}
|
|
3920
|
+
/**
|
|
3921
|
+
* Give extend lock period to get unlock at in seconds timestamp.
|
|
3922
|
+
*
|
|
3923
|
+
* @description
|
|
3924
|
+
* - When the user without remaining unlock period, If the extended unlock day is not specified,
|
|
3925
|
+
* the unlock period will be increased by one day by default.
|
|
3926
|
+
* - When the given extended day plus the user's remaining unlock period exceeds the maximum
|
|
3927
|
+
* unlock period, the maximum unlock period is used as unlock period.
|
|
3928
|
+
*
|
|
3929
|
+
* @param extendLockPeriodInDay The extend lock period in day.
|
|
3930
|
+
* @param unlockAtInSecondTimestamp The unlock timestamp from veSca object.
|
|
3931
|
+
* @return New unlock at in seconds timestamp.
|
|
3932
|
+
*/
|
|
3933
|
+
getUnlockAt(extendLockPeriodInDay, unlockAtInSecondTimestamp) {
|
|
3934
|
+
const now = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3);
|
|
3935
|
+
const remainingLockPeriod = unlockAtInSecondTimestamp ? Math.max(unlockAtInSecondTimestamp - now, 0) : 0;
|
|
3936
|
+
let newUnlockAtInSecondTimestamp = 0;
|
|
3937
|
+
if (remainingLockPeriod === 0) {
|
|
3938
|
+
const lockPeriod = (extendLockPeriodInDay ?? 1) * UNLOCK_ROUND_DURATION;
|
|
3939
|
+
newUnlockAtInSecondTimestamp = Math.min(
|
|
3940
|
+
now + lockPeriod,
|
|
3941
|
+
now + MAX_LOCK_DURATION
|
|
3942
|
+
);
|
|
3943
|
+
} else {
|
|
3944
|
+
const lockPeriod = Math.min(
|
|
3945
|
+
extendLockPeriodInDay ? extendLockPeriodInDay * UNLOCK_ROUND_DURATION + remainingLockPeriod : remainingLockPeriod,
|
|
3946
|
+
MAX_LOCK_DURATION
|
|
3947
|
+
);
|
|
3948
|
+
newUnlockAtInSecondTimestamp = now + lockPeriod;
|
|
3949
|
+
}
|
|
3950
|
+
return findClosestUnlockRound(newUnlockAtInSecondTimestamp);
|
|
3951
|
+
}
|
|
3700
3952
|
};
|
|
3701
3953
|
|
|
3702
3954
|
// src/models/scallopBuilder.ts
|
|
3703
|
-
var
|
|
3704
|
-
var
|
|
3955
|
+
var import_utils19 = require("@mysten/sui.js/utils");
|
|
3956
|
+
var import_sui_kit9 = require("@scallop-io/sui-kit");
|
|
3705
3957
|
|
|
3706
3958
|
// src/builders/coreBuilder.ts
|
|
3707
3959
|
var import_transactions = require("@mysten/sui.js/transactions");
|
|
@@ -4355,8 +4607,277 @@ var newSpoolTxBlock = (builder, initTxBlock) => {
|
|
|
4355
4607
|
|
|
4356
4608
|
// src/builders/borrowIncentiveBuilder.ts
|
|
4357
4609
|
var import_transactions3 = require("@mysten/sui.js/transactions");
|
|
4358
|
-
var
|
|
4610
|
+
var import_utils17 = require("@mysten/sui.js/utils");
|
|
4611
|
+
var import_sui_kit8 = require("@scallop-io/sui-kit");
|
|
4612
|
+
|
|
4613
|
+
// src/builders/vescaBuilder.ts
|
|
4359
4614
|
var import_sui_kit7 = require("@scallop-io/sui-kit");
|
|
4615
|
+
var requireVeSca = async (...params) => {
|
|
4616
|
+
const [builder, txBlock, veScaKey] = params;
|
|
4617
|
+
if (params.length === 3 && veScaKey && typeof veScaKey === "string") {
|
|
4618
|
+
const veSca = await getVeSca(builder.query, veScaKey);
|
|
4619
|
+
if (!veSca) {
|
|
4620
|
+
return void 0;
|
|
4621
|
+
}
|
|
4622
|
+
return veSca;
|
|
4623
|
+
}
|
|
4624
|
+
const sender = requireSender(txBlock);
|
|
4625
|
+
const veScas = await getVeScas(builder.query, sender);
|
|
4626
|
+
if (veScas.length === 0) {
|
|
4627
|
+
return void 0;
|
|
4628
|
+
}
|
|
4629
|
+
return veScas[0];
|
|
4630
|
+
};
|
|
4631
|
+
var generateNormalVeScaMethod = ({
|
|
4632
|
+
builder,
|
|
4633
|
+
txBlock
|
|
4634
|
+
}) => {
|
|
4635
|
+
const veScaIds = {
|
|
4636
|
+
pkgId: builder.address.get("vesca.id"),
|
|
4637
|
+
table: builder.address.get("vesca.table"),
|
|
4638
|
+
treasury: builder.address.get("vesca.treasury"),
|
|
4639
|
+
config: builder.address.get("vesca.config")
|
|
4640
|
+
};
|
|
4641
|
+
return {
|
|
4642
|
+
lockSca: (scaCoin, unlockAtInSecondTimestamp) => {
|
|
4643
|
+
return txBlock.moveCall(
|
|
4644
|
+
`${veScaIds.pkgId}::ve_sca::mint_ve_sca_key`,
|
|
4645
|
+
[
|
|
4646
|
+
veScaIds.config,
|
|
4647
|
+
veScaIds.table,
|
|
4648
|
+
veScaIds.treasury,
|
|
4649
|
+
scaCoin,
|
|
4650
|
+
unlockAtInSecondTimestamp,
|
|
4651
|
+
import_sui_kit7.SUI_CLOCK_OBJECT_ID
|
|
4652
|
+
],
|
|
4653
|
+
[]
|
|
4654
|
+
);
|
|
4655
|
+
},
|
|
4656
|
+
extendLockPeriod: (veScaKey, newUnlockAtInSecondTimestamp) => {
|
|
4657
|
+
txBlock.moveCall(
|
|
4658
|
+
`${veScaIds.pkgId}::ve_sca::extend_lock_period`,
|
|
4659
|
+
[
|
|
4660
|
+
veScaIds.config,
|
|
4661
|
+
veScaKey,
|
|
4662
|
+
veScaIds.table,
|
|
4663
|
+
veScaIds.treasury,
|
|
4664
|
+
newUnlockAtInSecondTimestamp,
|
|
4665
|
+
import_sui_kit7.SUI_CLOCK_OBJECT_ID
|
|
4666
|
+
],
|
|
4667
|
+
[]
|
|
4668
|
+
);
|
|
4669
|
+
},
|
|
4670
|
+
extendLockAmount: (veScaKey, scaCoin) => {
|
|
4671
|
+
txBlock.moveCall(
|
|
4672
|
+
`${veScaIds.pkgId}::ve_sca::lock_more_sca`,
|
|
4673
|
+
[
|
|
4674
|
+
veScaIds.config,
|
|
4675
|
+
veScaKey,
|
|
4676
|
+
veScaIds.table,
|
|
4677
|
+
veScaIds.treasury,
|
|
4678
|
+
scaCoin,
|
|
4679
|
+
import_sui_kit7.SUI_CLOCK_OBJECT_ID
|
|
4680
|
+
],
|
|
4681
|
+
[]
|
|
4682
|
+
);
|
|
4683
|
+
},
|
|
4684
|
+
renewExpiredVeSca: (veScaKey, scaCoin, newUnlockAtInSecondTimestamp) => {
|
|
4685
|
+
txBlock.moveCall(
|
|
4686
|
+
`${veScaIds.pkgId}::ve_sca::renew_expired_ve_sca`,
|
|
4687
|
+
[
|
|
4688
|
+
veScaIds.config,
|
|
4689
|
+
veScaKey,
|
|
4690
|
+
veScaIds.table,
|
|
4691
|
+
veScaIds.treasury,
|
|
4692
|
+
scaCoin,
|
|
4693
|
+
newUnlockAtInSecondTimestamp,
|
|
4694
|
+
import_sui_kit7.SUI_CLOCK_OBJECT_ID
|
|
4695
|
+
],
|
|
4696
|
+
[]
|
|
4697
|
+
);
|
|
4698
|
+
},
|
|
4699
|
+
redeemSca: (veScaKey) => {
|
|
4700
|
+
return txBlock.moveCall(
|
|
4701
|
+
`${veScaIds.pkgId}::ve_sca::redeem`,
|
|
4702
|
+
[
|
|
4703
|
+
veScaIds.config,
|
|
4704
|
+
veScaKey,
|
|
4705
|
+
veScaIds.table,
|
|
4706
|
+
veScaIds.treasury,
|
|
4707
|
+
import_sui_kit7.SUI_CLOCK_OBJECT_ID
|
|
4708
|
+
],
|
|
4709
|
+
[]
|
|
4710
|
+
);
|
|
4711
|
+
}
|
|
4712
|
+
};
|
|
4713
|
+
};
|
|
4714
|
+
var generateQuickVeScaMethod = ({
|
|
4715
|
+
builder,
|
|
4716
|
+
txBlock
|
|
4717
|
+
}) => {
|
|
4718
|
+
return {
|
|
4719
|
+
lockScaQuick: async (amountOrCoin, lockPeriodInDays, autoCheck = true) => {
|
|
4720
|
+
const sender = requireSender(txBlock);
|
|
4721
|
+
const veSca = await requireVeSca(builder, txBlock);
|
|
4722
|
+
let scaCoin = void 0;
|
|
4723
|
+
const transferObjects = [];
|
|
4724
|
+
if (amountOrCoin !== void 0 && typeof amountOrCoin === "number") {
|
|
4725
|
+
const coins = await builder.utils.selectCoinIds(
|
|
4726
|
+
amountOrCoin,
|
|
4727
|
+
SCA_COIN_TYPE,
|
|
4728
|
+
sender
|
|
4729
|
+
);
|
|
4730
|
+
const [takeCoin, leftCoin] = txBlock.takeAmountFromCoins(
|
|
4731
|
+
coins,
|
|
4732
|
+
amountOrCoin
|
|
4733
|
+
);
|
|
4734
|
+
scaCoin = takeCoin;
|
|
4735
|
+
transferObjects.push(leftCoin);
|
|
4736
|
+
} else {
|
|
4737
|
+
scaCoin = amountOrCoin;
|
|
4738
|
+
}
|
|
4739
|
+
const newUnlockAt = builder.utils.getUnlockAt(
|
|
4740
|
+
lockPeriodInDays,
|
|
4741
|
+
veSca?.unlockAt
|
|
4742
|
+
);
|
|
4743
|
+
if (autoCheck)
|
|
4744
|
+
checkLockSca(
|
|
4745
|
+
amountOrCoin,
|
|
4746
|
+
lockPeriodInDays,
|
|
4747
|
+
newUnlockAt,
|
|
4748
|
+
veSca?.unlockAt
|
|
4749
|
+
);
|
|
4750
|
+
console.log(
|
|
4751
|
+
new Date(newUnlockAt * 1e3).toLocaleString("en-CA", {
|
|
4752
|
+
hour12: true
|
|
4753
|
+
})
|
|
4754
|
+
);
|
|
4755
|
+
const isInitialLock = !veSca?.unlockAt;
|
|
4756
|
+
const isLockExpired = !isInitialLock && veSca.unlockAt * 1e3 <= (/* @__PURE__ */ new Date()).getTime();
|
|
4757
|
+
if (isInitialLock || isLockExpired) {
|
|
4758
|
+
if (scaCoin) {
|
|
4759
|
+
if (isInitialLock) {
|
|
4760
|
+
const veScaKey = txBlock.lockSca(scaCoin, newUnlockAt);
|
|
4761
|
+
transferObjects.push(veScaKey);
|
|
4762
|
+
} else {
|
|
4763
|
+
if (veSca.lockedScaAmount !== 0) {
|
|
4764
|
+
const unlockedSca = txBlock.redeemSca(veSca.keyId);
|
|
4765
|
+
transferObjects.push(unlockedSca);
|
|
4766
|
+
}
|
|
4767
|
+
txBlock.renewExpiredVeSca(veSca.keyId, scaCoin, newUnlockAt);
|
|
4768
|
+
}
|
|
4769
|
+
}
|
|
4770
|
+
} else {
|
|
4771
|
+
if (!!scaCoin && !!lockPeriodInDays) {
|
|
4772
|
+
txBlock.extendLockPeriod(veSca.keyId, newUnlockAt);
|
|
4773
|
+
txBlock.extendLockAmount(veSca.keyId, scaCoin);
|
|
4774
|
+
} else if (lockPeriodInDays) {
|
|
4775
|
+
txBlock.extendLockPeriod(veSca.keyId, newUnlockAt);
|
|
4776
|
+
} else if (scaCoin) {
|
|
4777
|
+
txBlock.extendLockAmount(veSca.keyId, scaCoin);
|
|
4778
|
+
}
|
|
4779
|
+
}
|
|
4780
|
+
if (transferObjects.length > 0) {
|
|
4781
|
+
txBlock.transferObjects(transferObjects, sender);
|
|
4782
|
+
}
|
|
4783
|
+
},
|
|
4784
|
+
extendLockPeriodQuick: async (lockPeriodInDays, veScaKey, autoCheck = true) => {
|
|
4785
|
+
const veSca = await requireVeSca(builder, txBlock, veScaKey);
|
|
4786
|
+
const newUnlockAt = builder.utils.getUnlockAt(lockPeriodInDays);
|
|
4787
|
+
if (autoCheck)
|
|
4788
|
+
checkExtendLockPeriod(lockPeriodInDays, newUnlockAt, veSca?.unlockAt);
|
|
4789
|
+
if (veSca) {
|
|
4790
|
+
txBlock.extendLockPeriod(veSca.keyId, newUnlockAt);
|
|
4791
|
+
}
|
|
4792
|
+
},
|
|
4793
|
+
extendLockAmountQuick: async (scaAmount, veScaKey, autoCheck = true) => {
|
|
4794
|
+
const sender = requireSender(txBlock);
|
|
4795
|
+
const veSca = await requireVeSca(builder, txBlock, veScaKey);
|
|
4796
|
+
if (autoCheck)
|
|
4797
|
+
checkExtendLockAmount(scaAmount, veSca?.unlockAt);
|
|
4798
|
+
if (veSca) {
|
|
4799
|
+
const scaCoins = await builder.utils.selectCoinIds(
|
|
4800
|
+
scaAmount,
|
|
4801
|
+
SCA_COIN_TYPE,
|
|
4802
|
+
sender
|
|
4803
|
+
);
|
|
4804
|
+
const [takeCoin, leftCoin] = txBlock.takeAmountFromCoins(
|
|
4805
|
+
scaCoins,
|
|
4806
|
+
scaAmount
|
|
4807
|
+
);
|
|
4808
|
+
txBlock.extendLockAmount(veSca.keyId, takeCoin);
|
|
4809
|
+
txBlock.transferObjects([leftCoin], sender);
|
|
4810
|
+
}
|
|
4811
|
+
},
|
|
4812
|
+
renewExpiredVeScaQuick: async (scaAmount, lockPeriodInDays, veScaKey, autoCheck = true) => {
|
|
4813
|
+
const sender = requireSender(txBlock);
|
|
4814
|
+
const veSca = await requireVeSca(builder, txBlock, veScaKey);
|
|
4815
|
+
const newUnlockAt = builder.utils.getUnlockAt(
|
|
4816
|
+
lockPeriodInDays,
|
|
4817
|
+
veSca?.unlockAt
|
|
4818
|
+
);
|
|
4819
|
+
if (autoCheck)
|
|
4820
|
+
checkRenewExpiredVeSca(scaAmount, lockPeriodInDays, veSca?.unlockAt);
|
|
4821
|
+
if (veSca) {
|
|
4822
|
+
const transferObjects = [];
|
|
4823
|
+
if (veSca.lockedScaAmount !== 0) {
|
|
4824
|
+
const unlockedSca = txBlock.redeemSca(veSca.keyId);
|
|
4825
|
+
transferObjects.push(unlockedSca);
|
|
4826
|
+
}
|
|
4827
|
+
const scaCoins = await builder.utils.selectCoinIds(
|
|
4828
|
+
scaAmount,
|
|
4829
|
+
SCA_COIN_TYPE,
|
|
4830
|
+
sender
|
|
4831
|
+
);
|
|
4832
|
+
const [takeCoin, leftCoin] = txBlock.takeAmountFromCoins(
|
|
4833
|
+
scaCoins,
|
|
4834
|
+
scaAmount
|
|
4835
|
+
);
|
|
4836
|
+
transferObjects.push(leftCoin);
|
|
4837
|
+
txBlock.renewExpiredVeSca(veSca.keyId, takeCoin, newUnlockAt);
|
|
4838
|
+
txBlock.transferObjects(transferObjects, sender);
|
|
4839
|
+
}
|
|
4840
|
+
},
|
|
4841
|
+
redeemScaQuick: async (veScaKey) => {
|
|
4842
|
+
const sender = requireSender(txBlock);
|
|
4843
|
+
const veSca = await requireVeSca(builder, txBlock, veScaKey);
|
|
4844
|
+
checkVesca(veSca?.unlockAt);
|
|
4845
|
+
if (veSca) {
|
|
4846
|
+
const sca = txBlock.redeemSca(veSca.keyId);
|
|
4847
|
+
txBlock.transferObjects([sca], sender);
|
|
4848
|
+
}
|
|
4849
|
+
}
|
|
4850
|
+
};
|
|
4851
|
+
};
|
|
4852
|
+
var newVeScaTxBlock = (builder, initTxBlock) => {
|
|
4853
|
+
const txBlock = initTxBlock instanceof import_sui_kit7.TransactionBlock ? new import_sui_kit7.SuiTxBlock(initTxBlock) : initTxBlock ? initTxBlock : new import_sui_kit7.SuiTxBlock();
|
|
4854
|
+
const normalMethod = generateNormalVeScaMethod({
|
|
4855
|
+
builder,
|
|
4856
|
+
txBlock
|
|
4857
|
+
});
|
|
4858
|
+
const normalTxBlock = new Proxy(txBlock, {
|
|
4859
|
+
get: (target, prop) => {
|
|
4860
|
+
if (prop in normalMethod) {
|
|
4861
|
+
return Reflect.get(normalMethod, prop);
|
|
4862
|
+
}
|
|
4863
|
+
return Reflect.get(target, prop);
|
|
4864
|
+
}
|
|
4865
|
+
});
|
|
4866
|
+
const quickMethod = generateQuickVeScaMethod({
|
|
4867
|
+
builder,
|
|
4868
|
+
txBlock: normalTxBlock
|
|
4869
|
+
});
|
|
4870
|
+
return new Proxy(normalTxBlock, {
|
|
4871
|
+
get: (target, prop) => {
|
|
4872
|
+
if (prop in quickMethod) {
|
|
4873
|
+
return Reflect.get(quickMethod, prop);
|
|
4874
|
+
}
|
|
4875
|
+
return Reflect.get(target, prop);
|
|
4876
|
+
}
|
|
4877
|
+
});
|
|
4878
|
+
};
|
|
4879
|
+
|
|
4880
|
+
// src/builders/borrowIncentiveBuilder.ts
|
|
4360
4881
|
var requireObligationInfo2 = async (...params) => {
|
|
4361
4882
|
const [builder, txBlock, obligationId, obligationKey] = params;
|
|
4362
4883
|
if (params.length === 4 && obligationId && obligationKey && typeof obligationId === "string") {
|
|
@@ -4377,59 +4898,115 @@ var requireObligationInfo2 = async (...params) => {
|
|
|
4377
4898
|
obligationLocked: obligations[0].locked
|
|
4378
4899
|
};
|
|
4379
4900
|
};
|
|
4901
|
+
var getBindedObligationId = async (builder, veScaKey) => {
|
|
4902
|
+
const borrowIncentivePkgId = builder.address.get("borrowIncentive.id");
|
|
4903
|
+
const incentivePoolsId = builder.address.get(
|
|
4904
|
+
"borrowIncentive.incentivePools"
|
|
4905
|
+
);
|
|
4906
|
+
const veScaPkgId = IS_VE_SCA_TEST ? "0xb220d034bdf335d77ae5bfbf6daf059c2cc7a1f719b12bfed75d1736fac038c8" : builder.address.get("vesca.id");
|
|
4907
|
+
const client = builder.suiKit.client();
|
|
4908
|
+
const incentivePoolsResponse = await client.getObject({
|
|
4909
|
+
id: incentivePoolsId,
|
|
4910
|
+
options: {
|
|
4911
|
+
showContent: true
|
|
4912
|
+
}
|
|
4913
|
+
});
|
|
4914
|
+
if (incentivePoolsResponse.data?.content?.dataType !== "moveObject")
|
|
4915
|
+
return false;
|
|
4916
|
+
const incentivePoolFields = incentivePoolsResponse.data.content.fields;
|
|
4917
|
+
const veScaBindTableId = incentivePoolFields.ve_sca_bind.fields.id.id;
|
|
4918
|
+
const keyType = `${borrowIncentivePkgId}::typed_id::TypedID<${veScaPkgId}::ve_sca::VeScaKey>`;
|
|
4919
|
+
const veScaBindTableResponse = await client.getDynamicFieldObject({
|
|
4920
|
+
parentId: veScaBindTableId,
|
|
4921
|
+
name: {
|
|
4922
|
+
type: keyType,
|
|
4923
|
+
value: veScaKey
|
|
4924
|
+
}
|
|
4925
|
+
});
|
|
4926
|
+
if (veScaBindTableResponse.data?.content?.dataType !== "moveObject")
|
|
4927
|
+
return false;
|
|
4928
|
+
const veScaBindTableFields = veScaBindTableResponse.data.content.fields;
|
|
4929
|
+
const obligationId = veScaBindTableFields.value.fields.id;
|
|
4930
|
+
return obligationId;
|
|
4931
|
+
};
|
|
4380
4932
|
var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
|
|
4381
4933
|
const borrowIncentiveIds = {
|
|
4382
|
-
borrowIncentivePkg: builder.address.get("borrowIncentive.id"),
|
|
4934
|
+
borrowIncentivePkg: IS_VE_SCA_TEST ? "0x4d5a7cefa4147b4ace0ca845b20437d6ac0d32e5f2f855171f745472c2576246" : builder.address.get("borrowIncentive.id"),
|
|
4383
4935
|
query: builder.address.get("borrowIncentive.query"),
|
|
4936
|
+
config: builder.address.get("borrowIncentive.config"),
|
|
4384
4937
|
incentivePools: builder.address.get("borrowIncentive.incentivePools"),
|
|
4385
4938
|
incentiveAccounts: builder.address.get(
|
|
4386
4939
|
"borrowIncentive.incentiveAccounts"
|
|
4387
4940
|
),
|
|
4388
4941
|
obligationAccessStore: builder.address.get("core.obligationAccessStore")
|
|
4389
4942
|
};
|
|
4943
|
+
const veScaIds = {
|
|
4944
|
+
table: builder.address.get("vesca.table"),
|
|
4945
|
+
treasury: builder.address.get("vesca.treasury"),
|
|
4946
|
+
config: builder.address.get("vesca.config")
|
|
4947
|
+
};
|
|
4390
4948
|
return {
|
|
4391
|
-
stakeObligation: (obligationId,
|
|
4392
|
-
const rewardCoinName = "sui";
|
|
4393
|
-
const rewardType = builder.utils.parseCoinType(rewardCoinName);
|
|
4949
|
+
stakeObligation: (obligationId, obligationKey) => {
|
|
4394
4950
|
txBlock.moveCall(
|
|
4395
4951
|
`${borrowIncentiveIds.borrowIncentivePkg}::user::stake`,
|
|
4396
4952
|
[
|
|
4953
|
+
borrowIncentiveIds.config,
|
|
4397
4954
|
borrowIncentiveIds.incentivePools,
|
|
4398
4955
|
borrowIncentiveIds.incentiveAccounts,
|
|
4399
|
-
|
|
4956
|
+
obligationKey,
|
|
4400
4957
|
obligationId,
|
|
4401
4958
|
borrowIncentiveIds.obligationAccessStore,
|
|
4402
|
-
|
|
4959
|
+
import_utils17.SUI_CLOCK_OBJECT_ID
|
|
4960
|
+
]
|
|
4961
|
+
);
|
|
4962
|
+
},
|
|
4963
|
+
stakeObligationWithVesca: (obligationId, obligationKey, veScaKey) => {
|
|
4964
|
+
txBlock.moveCall(
|
|
4965
|
+
`${borrowIncentiveIds.borrowIncentivePkg}::user::stake_with_ve_sca`,
|
|
4966
|
+
[
|
|
4967
|
+
borrowIncentiveIds.config,
|
|
4968
|
+
borrowIncentiveIds.incentivePools,
|
|
4969
|
+
borrowIncentiveIds.incentiveAccounts,
|
|
4970
|
+
obligationKey,
|
|
4971
|
+
obligationId,
|
|
4972
|
+
borrowIncentiveIds.obligationAccessStore,
|
|
4973
|
+
veScaIds.config,
|
|
4974
|
+
veScaIds.treasury,
|
|
4975
|
+
veScaIds.table,
|
|
4976
|
+
veScaKey,
|
|
4977
|
+
import_utils17.SUI_CLOCK_OBJECT_ID
|
|
4403
4978
|
],
|
|
4404
|
-
[
|
|
4979
|
+
[]
|
|
4405
4980
|
);
|
|
4406
4981
|
},
|
|
4407
|
-
unstakeObligation: (obligationId,
|
|
4408
|
-
const rewardCoinName = "sui";
|
|
4409
|
-
const rewardType = builder.utils.parseCoinType(rewardCoinName);
|
|
4982
|
+
unstakeObligation: (obligationId, obligationKey) => {
|
|
4410
4983
|
txBlock.moveCall(
|
|
4411
4984
|
`${borrowIncentiveIds.borrowIncentivePkg}::user::unstake`,
|
|
4412
4985
|
[
|
|
4986
|
+
borrowIncentiveIds.config,
|
|
4413
4987
|
borrowIncentiveIds.incentivePools,
|
|
4414
4988
|
borrowIncentiveIds.incentiveAccounts,
|
|
4415
|
-
|
|
4989
|
+
obligationKey,
|
|
4416
4990
|
obligationId,
|
|
4417
|
-
|
|
4418
|
-
]
|
|
4419
|
-
[rewardType]
|
|
4991
|
+
import_utils17.SUI_CLOCK_OBJECT_ID
|
|
4992
|
+
]
|
|
4420
4993
|
);
|
|
4421
4994
|
},
|
|
4422
|
-
claimBorrowIncentive: (obligationId,
|
|
4423
|
-
const
|
|
4995
|
+
claimBorrowIncentive: (obligationId, obligationKey, coinName, rewardCoinName) => {
|
|
4996
|
+
const rewardCoinNames = borrowIncentiveRewardCoins[coinName];
|
|
4997
|
+
if (rewardCoinNames.includes(rewardCoinName) === false) {
|
|
4998
|
+
throw new Error(`Invalid reward coin name ${rewardCoinName}`);
|
|
4999
|
+
}
|
|
4424
5000
|
const rewardType = builder.utils.parseCoinType(rewardCoinName);
|
|
4425
5001
|
return txBlock.moveCall(
|
|
4426
5002
|
`${borrowIncentiveIds.borrowIncentivePkg}::user::redeem_rewards`,
|
|
4427
5003
|
[
|
|
5004
|
+
borrowIncentiveIds.config,
|
|
4428
5005
|
borrowIncentiveIds.incentivePools,
|
|
4429
5006
|
borrowIncentiveIds.incentiveAccounts,
|
|
4430
|
-
|
|
5007
|
+
obligationKey,
|
|
4431
5008
|
obligationId,
|
|
4432
|
-
|
|
5009
|
+
import_utils17.SUI_CLOCK_OBJECT_ID
|
|
4433
5010
|
],
|
|
4434
5011
|
[rewardType]
|
|
4435
5012
|
);
|
|
@@ -4450,12 +5027,51 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
|
|
|
4450
5027
|
obligationKey
|
|
4451
5028
|
);
|
|
4452
5029
|
const unstakeObligationBeforeStake = !!txBlock.txBlock.blockData.transactions.find(
|
|
4453
|
-
(txn) => txn.kind === "MoveCall" && txn.target === `${
|
|
5030
|
+
(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(
|
|
5031
|
+
"borrowIncentive.id"
|
|
5032
|
+
)}::user::unstake`))
|
|
4454
5033
|
);
|
|
4455
5034
|
if (!obligationLocked || unstakeObligationBeforeStake) {
|
|
4456
5035
|
txBlock.stakeObligation(obligationArg, obligationtKeyArg);
|
|
4457
5036
|
}
|
|
4458
5037
|
},
|
|
5038
|
+
stakeObligationWithVeScaQuick: async (obligation, obligationKey, veScaKey) => {
|
|
5039
|
+
const {
|
|
5040
|
+
obligationId: obligationArg,
|
|
5041
|
+
obligationKey: obligationtKeyArg,
|
|
5042
|
+
obligationLocked
|
|
5043
|
+
} = await requireObligationInfo2(
|
|
5044
|
+
builder,
|
|
5045
|
+
txBlock,
|
|
5046
|
+
obligation,
|
|
5047
|
+
obligationKey
|
|
5048
|
+
);
|
|
5049
|
+
const unstakeObligationBeforeStake = !!txBlock.txBlock.blockData.transactions.find(
|
|
5050
|
+
(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(
|
|
5051
|
+
"borrowIncentive.id"
|
|
5052
|
+
)}::user::unstake`))
|
|
5053
|
+
);
|
|
5054
|
+
if (!obligationLocked || unstakeObligationBeforeStake) {
|
|
5055
|
+
const veSca = await requireVeSca(builder, txBlock, veScaKey);
|
|
5056
|
+
if (veSca) {
|
|
5057
|
+
const bindedObligationId = await getBindedObligationId(
|
|
5058
|
+
builder,
|
|
5059
|
+
veSca.keyId
|
|
5060
|
+
);
|
|
5061
|
+
if (!bindedObligationId || bindedObligationId === obligationArg) {
|
|
5062
|
+
txBlock.stakeObligationWithVesca(
|
|
5063
|
+
obligationArg,
|
|
5064
|
+
obligationtKeyArg,
|
|
5065
|
+
veSca.keyId
|
|
5066
|
+
);
|
|
5067
|
+
} else {
|
|
5068
|
+
txBlock.stakeObligation(obligationArg, obligationtKeyArg);
|
|
5069
|
+
}
|
|
5070
|
+
} else {
|
|
5071
|
+
txBlock.stakeObligation(obligationArg, obligationtKeyArg);
|
|
5072
|
+
}
|
|
5073
|
+
}
|
|
5074
|
+
},
|
|
4459
5075
|
unstakeObligationQuick: async (obligation, obligationKey) => {
|
|
4460
5076
|
const {
|
|
4461
5077
|
obligationId: obligationArg,
|
|
@@ -4471,7 +5087,7 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
|
|
|
4471
5087
|
txBlock.unstakeObligation(obligationArg, obligationtKeyArg);
|
|
4472
5088
|
}
|
|
4473
5089
|
},
|
|
4474
|
-
claimBorrowIncentiveQuick: async (coinName, obligation, obligationKey) => {
|
|
5090
|
+
claimBorrowIncentiveQuick: async (coinName, rewardCoinName, obligation, obligationKey) => {
|
|
4475
5091
|
const {
|
|
4476
5092
|
obligationId: obligationArg,
|
|
4477
5093
|
obligationKey: obligationtKeyArg
|
|
@@ -4484,13 +5100,14 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
|
|
|
4484
5100
|
return txBlock.claimBorrowIncentive(
|
|
4485
5101
|
obligationArg,
|
|
4486
5102
|
obligationtKeyArg,
|
|
4487
|
-
coinName
|
|
5103
|
+
coinName,
|
|
5104
|
+
rewardCoinName
|
|
4488
5105
|
);
|
|
4489
5106
|
}
|
|
4490
5107
|
};
|
|
4491
5108
|
};
|
|
4492
5109
|
var newBorrowIncentiveTxBlock = (builder, initTxBlock) => {
|
|
4493
|
-
const txBlock = initTxBlock instanceof import_transactions3.TransactionBlock ? new
|
|
5110
|
+
const txBlock = initTxBlock instanceof import_transactions3.TransactionBlock ? new import_sui_kit8.SuiTxBlock(initTxBlock) : initTxBlock ? initTxBlock : new import_sui_kit8.SuiTxBlock();
|
|
4494
5111
|
const normalMethod = generateBorrowIncentiveNormalMethod({
|
|
4495
5112
|
builder,
|
|
4496
5113
|
txBlock
|
|
@@ -4519,15 +5136,18 @@ var newBorrowIncentiveTxBlock = (builder, initTxBlock) => {
|
|
|
4519
5136
|
|
|
4520
5137
|
// src/builders/index.ts
|
|
4521
5138
|
var newScallopTxBlock = (builder, initTxBlock) => {
|
|
5139
|
+
const vescaTxBlock = newVeScaTxBlock(builder, initTxBlock);
|
|
4522
5140
|
const borrowIncentiveTxBlock = newBorrowIncentiveTxBlock(
|
|
4523
5141
|
builder,
|
|
4524
|
-
|
|
5142
|
+
vescaTxBlock
|
|
4525
5143
|
);
|
|
4526
5144
|
const spoolTxBlock = newSpoolTxBlock(builder, borrowIncentiveTxBlock);
|
|
4527
5145
|
const coreTxBlock = newCoreTxBlock(builder, spoolTxBlock);
|
|
4528
5146
|
return new Proxy(coreTxBlock, {
|
|
4529
5147
|
get: (target, prop) => {
|
|
4530
|
-
if (prop in
|
|
5148
|
+
if (prop in vescaTxBlock) {
|
|
5149
|
+
return Reflect.get(vescaTxBlock, prop);
|
|
5150
|
+
} else if (prop in borrowIncentiveTxBlock) {
|
|
4531
5151
|
return Reflect.get(borrowIncentiveTxBlock, prop);
|
|
4532
5152
|
} else if (prop in spoolTxBlock) {
|
|
4533
5153
|
return Reflect.get(spoolTxBlock, prop);
|
|
@@ -4541,7 +5161,7 @@ var newScallopTxBlock = (builder, initTxBlock) => {
|
|
|
4541
5161
|
var ScallopBuilder = class {
|
|
4542
5162
|
constructor(params, instance) {
|
|
4543
5163
|
this.params = params;
|
|
4544
|
-
this.suiKit = instance?.suiKit ?? new
|
|
5164
|
+
this.suiKit = instance?.suiKit ?? new import_sui_kit9.SuiKit(params);
|
|
4545
5165
|
this.address = instance?.address ?? new ScallopAddress({
|
|
4546
5166
|
id: params?.addressesId || ADDRESSES_ID,
|
|
4547
5167
|
network: params?.networkType
|
|
@@ -4555,7 +5175,7 @@ var ScallopBuilder = class {
|
|
|
4555
5175
|
address: this.address,
|
|
4556
5176
|
query: this.query
|
|
4557
5177
|
});
|
|
4558
|
-
this.walletAddress = (0,
|
|
5178
|
+
this.walletAddress = (0, import_utils19.normalizeSuiAddress)(
|
|
4559
5179
|
params?.walletAddress || this.suiKit.currentAddress()
|
|
4560
5180
|
);
|
|
4561
5181
|
this.isTestnet = params.networkType ? params.networkType === "testnet" : false;
|
|
@@ -4634,7 +5254,7 @@ var ScallopBuilder = class {
|
|
|
4634
5254
|
var ScallopClient = class {
|
|
4635
5255
|
constructor(params, instance) {
|
|
4636
5256
|
this.params = params;
|
|
4637
|
-
this.suiKit = instance?.suiKit ?? new
|
|
5257
|
+
this.suiKit = instance?.suiKit ?? new import_sui_kit10.SuiKit(params);
|
|
4638
5258
|
this.address = instance?.address ?? new ScallopAddress({
|
|
4639
5259
|
id: params?.addressesId || ADDRESSES_ID,
|
|
4640
5260
|
network: params?.networkType
|
|
@@ -4654,7 +5274,7 @@ var ScallopClient = class {
|
|
|
4654
5274
|
query: this.query,
|
|
4655
5275
|
utils: this.utils
|
|
4656
5276
|
});
|
|
4657
|
-
this.walletAddress = (0,
|
|
5277
|
+
this.walletAddress = (0, import_utils20.normalizeSuiAddress)(
|
|
4658
5278
|
params?.walletAddress || this.suiKit.currentAddress()
|
|
4659
5279
|
);
|
|
4660
5280
|
}
|
|
@@ -5027,7 +5647,7 @@ var ScallopClient = class {
|
|
|
5027
5647
|
const coins = [];
|
|
5028
5648
|
for (const stakeMarketCoin of stakeMarketCoins2) {
|
|
5029
5649
|
const stakeCoinName = this.utils.parseCoinName(stakeMarketCoinName);
|
|
5030
|
-
const coin =
|
|
5650
|
+
const coin = txBlock.withdraw(stakeMarketCoin, stakeCoinName);
|
|
5031
5651
|
coins.push(coin);
|
|
5032
5652
|
}
|
|
5033
5653
|
txBlock.transferObjects(coins, sender);
|
|
@@ -5060,17 +5680,17 @@ var ScallopClient = class {
|
|
|
5060
5680
|
/**
|
|
5061
5681
|
* stake obligaion.
|
|
5062
5682
|
*
|
|
5063
|
-
* @param
|
|
5064
|
-
* @param
|
|
5683
|
+
* @param obligationId - The obligation account object.
|
|
5684
|
+
* @param obligationKeyId - The obligation key account object.
|
|
5065
5685
|
* @param sign - Decide to directly sign the transaction or return the transaction block.
|
|
5066
5686
|
* @param walletAddress - The wallet address of the owner.
|
|
5067
5687
|
* @return Transaction block response or transaction block
|
|
5068
5688
|
*/
|
|
5069
|
-
async stakeObligation(
|
|
5689
|
+
async stakeObligation(obligationId, obligationKeyId, sign = true, walletAddress) {
|
|
5070
5690
|
const txBlock = this.builder.createTxBlock();
|
|
5071
5691
|
const sender = walletAddress || this.walletAddress;
|
|
5072
5692
|
txBlock.setSender(sender);
|
|
5073
|
-
await txBlock.stakeObligationQuick(
|
|
5693
|
+
await txBlock.stakeObligationQuick(obligationId, obligationKeyId);
|
|
5074
5694
|
if (sign) {
|
|
5075
5695
|
return await this.suiKit.signAndSendTxn(
|
|
5076
5696
|
txBlock
|
|
@@ -5082,17 +5702,17 @@ var ScallopClient = class {
|
|
|
5082
5702
|
/**
|
|
5083
5703
|
* unstake obligaion.
|
|
5084
5704
|
*
|
|
5085
|
-
* @param
|
|
5086
|
-
* @param
|
|
5705
|
+
* @param obligationId - The obligation account object.
|
|
5706
|
+
* @param obligationKeyId - The obligation key account object.
|
|
5087
5707
|
* @param sign - Decide to directly sign the transaction or return the transaction block.
|
|
5088
5708
|
* @param walletAddress - The wallet address of the owner.
|
|
5089
5709
|
* @return Transaction block response or transaction block
|
|
5090
5710
|
*/
|
|
5091
|
-
async unstakeObligation(
|
|
5711
|
+
async unstakeObligation(obligationId, obligationKeyId, sign = true, walletAddress) {
|
|
5092
5712
|
const txBlock = this.builder.createTxBlock();
|
|
5093
5713
|
const sender = walletAddress || this.walletAddress;
|
|
5094
5714
|
txBlock.setSender(sender);
|
|
5095
|
-
await txBlock.unstakeObligationQuick(
|
|
5715
|
+
await txBlock.unstakeObligationQuick(obligationId, obligationKeyId);
|
|
5096
5716
|
if (sign) {
|
|
5097
5717
|
return await this.suiKit.signAndSendTxn(
|
|
5098
5718
|
txBlock
|
|
@@ -5111,16 +5731,21 @@ var ScallopClient = class {
|
|
|
5111
5731
|
* @param walletAddress - The wallet address of the owner.
|
|
5112
5732
|
* @return Transaction block response or transaction block
|
|
5113
5733
|
*/
|
|
5114
|
-
async claimBorrowIncentive(coinName,
|
|
5734
|
+
async claimBorrowIncentive(coinName, obligationId, obligationKeyId, sign = true, walletAddress) {
|
|
5115
5735
|
const txBlock = this.builder.createTxBlock();
|
|
5116
5736
|
const sender = walletAddress || this.walletAddress;
|
|
5117
5737
|
txBlock.setSender(sender);
|
|
5118
|
-
const
|
|
5119
|
-
|
|
5120
|
-
|
|
5121
|
-
|
|
5122
|
-
|
|
5123
|
-
|
|
5738
|
+
const rewardCoins = [];
|
|
5739
|
+
for (const rewardCoinName of SUPPORT_BORROW_INCENTIVE_REWARDS) {
|
|
5740
|
+
const rewardCoin = await txBlock.claimBorrowIncentiveQuick(
|
|
5741
|
+
coinName,
|
|
5742
|
+
rewardCoinName,
|
|
5743
|
+
obligationId,
|
|
5744
|
+
obligationKeyId
|
|
5745
|
+
);
|
|
5746
|
+
rewardCoins.push(rewardCoin);
|
|
5747
|
+
}
|
|
5748
|
+
txBlock.transferObjects(rewardCoins, sender);
|
|
5124
5749
|
if (sign) {
|
|
5125
5750
|
return await this.suiKit.signAndSendTxn(
|
|
5126
5751
|
txBlock
|
|
@@ -5155,7 +5780,7 @@ var ScallopClient = class {
|
|
|
5155
5780
|
var Scallop = class {
|
|
5156
5781
|
constructor(params) {
|
|
5157
5782
|
this.params = params;
|
|
5158
|
-
this.suiKit = new
|
|
5783
|
+
this.suiKit = new import_sui_kit11.SuiKit(params);
|
|
5159
5784
|
this._address = new ScallopAddress({
|
|
5160
5785
|
id: params?.addressesId || ADDRESSES_ID,
|
|
5161
5786
|
network: params?.networkType
|
|
@@ -5243,7 +5868,14 @@ var Scallop = class {
|
|
|
5243
5868
|
ADDRESSES_ID,
|
|
5244
5869
|
API_BASE_URL,
|
|
5245
5870
|
BORROW_FEE_PROTOCOL_ID,
|
|
5871
|
+
IS_VE_SCA_TEST,
|
|
5872
|
+
MAX_LOCK_DURATION,
|
|
5873
|
+
MAX_LOCK_ROUNDS,
|
|
5874
|
+
MIN_INITIAL_LOCK_AMOUNT,
|
|
5875
|
+
MIN_TOP_UP_AMOUNT,
|
|
5876
|
+
OLD_BORROW_INCENTIVE_PROTOCOL_ID,
|
|
5246
5877
|
PROTOCOL_OBJECT_ID,
|
|
5878
|
+
SCA_COIN_TYPE,
|
|
5247
5879
|
SDK_API_BASE_URL,
|
|
5248
5880
|
SUPPORT_BORROW_INCENTIVE_POOLS,
|
|
5249
5881
|
SUPPORT_BORROW_INCENTIVE_REWARDS,
|
|
@@ -5260,6 +5892,7 @@ var Scallop = class {
|
|
|
5260
5892
|
ScallopIndexer,
|
|
5261
5893
|
ScallopQuery,
|
|
5262
5894
|
ScallopUtils,
|
|
5895
|
+
UNLOCK_ROUND_DURATION,
|
|
5263
5896
|
assetCoins,
|
|
5264
5897
|
borrowIncentiveRewardCoins,
|
|
5265
5898
|
coinDecimals,
|