@strkfarm/sdk 1.0.39 → 1.0.41
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/index.browser.global.js +67 -22
- package/dist/index.browser.mjs +67 -22
- package/dist/index.d.ts +12 -0
- package/dist/index.js +96 -51
- package/dist/index.mjs +96 -51
- package/package.json +1 -1
- package/src/strategies/ekubo-cl-vault.tsx +78 -17
|
@@ -19722,14 +19722,6 @@ var strkfarm_risk_engine = (() => {
|
|
|
19722
19722
|
mergeConfig: mergeConfig2
|
|
19723
19723
|
} = axios_default;
|
|
19724
19724
|
|
|
19725
|
-
// src/utils/logger.browser.ts
|
|
19726
|
-
var logger = {
|
|
19727
|
-
...console,
|
|
19728
|
-
verbose(message) {
|
|
19729
|
-
console.log(`[VERBOSE] ${message}`);
|
|
19730
|
-
}
|
|
19731
|
-
};
|
|
19732
|
-
|
|
19733
19725
|
// src/dataTypes/_bignumber.ts
|
|
19734
19726
|
var import_bignumber = __toESM(require_bignumber());
|
|
19735
19727
|
var _Web3Number = class extends import_bignumber.default {
|
|
@@ -19746,7 +19738,6 @@ var strkfarm_risk_engine = (() => {
|
|
|
19746
19738
|
}
|
|
19747
19739
|
dividedBy(value) {
|
|
19748
19740
|
const _value = this.getStandardString(value);
|
|
19749
|
-
console.log("dividedBy", _value);
|
|
19750
19741
|
return this.construct(this.div(_value).toString(), this.decimals);
|
|
19751
19742
|
}
|
|
19752
19743
|
plus(value) {
|
|
@@ -19764,11 +19755,9 @@ var strkfarm_risk_engine = (() => {
|
|
|
19764
19755
|
return super.toString();
|
|
19765
19756
|
}
|
|
19766
19757
|
toJSON() {
|
|
19767
|
-
logger.verbose(`converting to json with decimals`);
|
|
19768
19758
|
return this.toString();
|
|
19769
19759
|
}
|
|
19770
19760
|
valueOf() {
|
|
19771
|
-
logger.verbose(`converting to valueOf with decimals`);
|
|
19772
19761
|
return this.toString();
|
|
19773
19762
|
}
|
|
19774
19763
|
maxToFixedDecimals() {
|
|
@@ -36021,6 +36010,14 @@ var strkfarm_risk_engine = (() => {
|
|
|
36021
36010
|
}
|
|
36022
36011
|
};
|
|
36023
36012
|
|
|
36013
|
+
// src/utils/logger.browser.ts
|
|
36014
|
+
var logger = {
|
|
36015
|
+
...console,
|
|
36016
|
+
verbose(message) {
|
|
36017
|
+
console.log(`[VERBOSE] ${message}`);
|
|
36018
|
+
}
|
|
36019
|
+
};
|
|
36020
|
+
|
|
36024
36021
|
// src/global.ts
|
|
36025
36022
|
var FatalError = class extends Error {
|
|
36026
36023
|
constructor(message, err2) {
|
|
@@ -55185,14 +55182,24 @@ var strkfarm_risk_engine = (() => {
|
|
|
55185
55182
|
_solveExpectedAmountsEq(availableAmount0, availableAmount1, ratio, price) {
|
|
55186
55183
|
const y = ratio.multipliedBy(availableAmount1).minus(availableAmount0).dividedBy(ratio.plus(1 / price));
|
|
55187
55184
|
const x = y.dividedBy(price);
|
|
55185
|
+
logger.verbose(
|
|
55186
|
+
`${_EkuboCLVault.name}: _solveExpectedAmountsEq => x: ${x.toString()}, y: ${y.toString()}, amount0: ${availableAmount0.toString()}, amount1: ${availableAmount1.toString()}`
|
|
55187
|
+
);
|
|
55188
|
+
if (ratio.eq(0)) {
|
|
55189
|
+
return {
|
|
55190
|
+
amount0: Web3Number.fromWei("0", availableAmount0.decimals),
|
|
55191
|
+
amount1: availableAmount1.minus(y),
|
|
55192
|
+
ratio: 0
|
|
55193
|
+
};
|
|
55194
|
+
}
|
|
55188
55195
|
return {
|
|
55189
55196
|
amount0: availableAmount0.plus(x),
|
|
55190
55197
|
amount1: availableAmount1.minus(y),
|
|
55191
55198
|
ratio: Number(ratio.toString())
|
|
55192
55199
|
};
|
|
55193
55200
|
}
|
|
55194
|
-
async
|
|
55195
|
-
const poolKey = await this.getPoolKey();
|
|
55201
|
+
async unusedBalances(_poolKey) {
|
|
55202
|
+
const poolKey = _poolKey || await this.getPoolKey();
|
|
55196
55203
|
const erc20Mod = new ERC20(this.config);
|
|
55197
55204
|
const token0Info = await Global.getTokenInfoFromAddr(poolKey.token0);
|
|
55198
55205
|
const token1Info = await Global.getTokenInfoFromAddr(poolKey.token1);
|
|
@@ -55213,11 +55220,24 @@ var strkfarm_risk_engine = (() => {
|
|
|
55213
55220
|
const token1Price = await this.pricer.getPrice(token1Info.symbol);
|
|
55214
55221
|
const token0PriceUsd = token0Price.price * Number(token0Bal1.toFixed(13));
|
|
55215
55222
|
const token1PriceUsd = token1Price.price * Number(token1Bal1.toFixed(13));
|
|
55216
|
-
|
|
55217
|
-
|
|
55218
|
-
|
|
55219
|
-
|
|
55220
|
-
|
|
55223
|
+
return {
|
|
55224
|
+
token0: {
|
|
55225
|
+
amount: token0Bal1,
|
|
55226
|
+
tokenInfo: token0Info,
|
|
55227
|
+
usdValue: token0PriceUsd
|
|
55228
|
+
},
|
|
55229
|
+
token1: {
|
|
55230
|
+
amount: token1Bal1,
|
|
55231
|
+
tokenInfo: token1Info,
|
|
55232
|
+
usdValue: token1PriceUsd
|
|
55233
|
+
}
|
|
55234
|
+
};
|
|
55235
|
+
}
|
|
55236
|
+
async getSwapInfoToHandleUnused(considerRebalance = true) {
|
|
55237
|
+
const poolKey = await this.getPoolKey();
|
|
55238
|
+
const unusedBalances = await this.unusedBalances(poolKey);
|
|
55239
|
+
const { amount: token0Bal1, usdValue: token0PriceUsd } = unusedBalances.token0;
|
|
55240
|
+
const { amount: token1Bal1, usdValue: token1PriceUsd } = unusedBalances.token1;
|
|
55221
55241
|
let token0Bal = token0Bal1;
|
|
55222
55242
|
let token1Bal = token1Bal1;
|
|
55223
55243
|
if (considerRebalance) {
|
|
@@ -55235,25 +55255,33 @@ var strkfarm_risk_engine = (() => {
|
|
|
55235
55255
|
logger.verbose(
|
|
55236
55256
|
`${_EkuboCLVault.name}: getSwapInfoToHandleUnused => token0Bal: ${token0Bal.toString()}, token1Bal: ${token1Bal.toString()}`
|
|
55237
55257
|
);
|
|
55238
|
-
|
|
55258
|
+
let ekuboBounds;
|
|
55259
|
+
if (considerRebalance) {
|
|
55260
|
+
ekuboBounds = await this.getNewBounds();
|
|
55261
|
+
} else {
|
|
55262
|
+
ekuboBounds = await this.getCurrentBounds();
|
|
55263
|
+
}
|
|
55239
55264
|
logger.verbose(
|
|
55240
|
-
`${_EkuboCLVault.name}: getSwapInfoToHandleUnused => newBounds: ${
|
|
55265
|
+
`${_EkuboCLVault.name}: getSwapInfoToHandleUnused => newBounds: ${ekuboBounds.lowerTick}, ${ekuboBounds.upperTick}`
|
|
55241
55266
|
);
|
|
55242
55267
|
return await this.getSwapInfoGivenAmounts(
|
|
55243
55268
|
poolKey,
|
|
55244
55269
|
token0Bal,
|
|
55245
55270
|
token1Bal,
|
|
55246
|
-
|
|
55271
|
+
ekuboBounds
|
|
55247
55272
|
);
|
|
55248
55273
|
}
|
|
55249
55274
|
async getSwapInfoGivenAmounts(poolKey, token0Bal, token1Bal, bounds) {
|
|
55275
|
+
logger.verbose(
|
|
55276
|
+
`${_EkuboCLVault.name}: getSwapInfoGivenAmounts::pre => token0Bal: ${token0Bal.toString()}, token1Bal: ${token1Bal.toString()}`
|
|
55277
|
+
);
|
|
55250
55278
|
let expectedAmounts = await this._getExpectedAmountsForLiquidity(
|
|
55251
55279
|
token0Bal,
|
|
55252
55280
|
token1Bal,
|
|
55253
55281
|
bounds
|
|
55254
55282
|
);
|
|
55255
55283
|
logger.verbose(
|
|
55256
|
-
`${_EkuboCLVault.name}: getSwapInfoToHandleUnused =>
|
|
55284
|
+
`${_EkuboCLVault.name}: getSwapInfoToHandleUnused => expectedAmounts2: ${expectedAmounts.amount0.toString()}, ${expectedAmounts.amount1.toString()}`
|
|
55257
55285
|
);
|
|
55258
55286
|
let retry = 0;
|
|
55259
55287
|
const maxRetry = 10;
|
|
@@ -55526,6 +55554,7 @@ var strkfarm_risk_engine = (() => {
|
|
|
55526
55554
|
const token0Info = await Global.getTokenInfoFromAddr(poolKey.token0);
|
|
55527
55555
|
const token1Info = await Global.getTokenInfoFromAddr(poolKey.token1);
|
|
55528
55556
|
const bounds = await this.getCurrentBounds();
|
|
55557
|
+
logger.verbose(`${_EkuboCLVault.name}: harvest => unClaimedRewards: ${unClaimedRewards.length}`);
|
|
55529
55558
|
const calls = [];
|
|
55530
55559
|
for (let claim of unClaimedRewards) {
|
|
55531
55560
|
const fee = claim.claim.amount.multipliedBy(this.metadata.additionalInfo.feeBps).dividedBy(1e4);
|
|
@@ -55558,12 +55587,28 @@ var strkfarm_risk_engine = (() => {
|
|
|
55558
55587
|
18
|
|
55559
55588
|
// cause its always STRK?
|
|
55560
55589
|
);
|
|
55590
|
+
logger.verbose(
|
|
55591
|
+
`${_EkuboCLVault.name}: harvest => swap1Amount: ${swap1Amount}`
|
|
55592
|
+
);
|
|
55561
55593
|
const remainingAmount = postFeeAmount.minus(swap1Amount);
|
|
55594
|
+
logger.verbose(
|
|
55595
|
+
`${_EkuboCLVault.name}: harvest => remainingAmount: ${remainingAmount}`
|
|
55596
|
+
);
|
|
55562
55597
|
const swapInfo2 = {
|
|
55563
55598
|
...swapInfo,
|
|
55564
55599
|
token_from_amount: uint256_exports.bnToUint256(remainingAmount.toWei())
|
|
55565
55600
|
};
|
|
55566
55601
|
swapInfo2.token_to_address = token1Info.address.address;
|
|
55602
|
+
logger.verbose(
|
|
55603
|
+
`${_EkuboCLVault.name}: harvest => swapInfo: ${JSON.stringify(
|
|
55604
|
+
swapInfo
|
|
55605
|
+
)}`
|
|
55606
|
+
);
|
|
55607
|
+
logger.verbose(
|
|
55608
|
+
`${_EkuboCLVault.name}: harvest => swapInfo2: ${JSON.stringify(
|
|
55609
|
+
swapInfo2
|
|
55610
|
+
)}`
|
|
55611
|
+
);
|
|
55567
55612
|
const calldata = [
|
|
55568
55613
|
claim.rewardsContract.address,
|
|
55569
55614
|
{
|
package/dist/index.browser.mjs
CHANGED
|
@@ -4,14 +4,6 @@ import axios2 from "axios";
|
|
|
4
4
|
// src/global.ts
|
|
5
5
|
import axios from "axios";
|
|
6
6
|
|
|
7
|
-
// src/utils/logger.browser.ts
|
|
8
|
-
var logger = {
|
|
9
|
-
...console,
|
|
10
|
-
verbose(message) {
|
|
11
|
-
console.log(`[VERBOSE] ${message}`);
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
|
|
15
7
|
// src/dataTypes/_bignumber.ts
|
|
16
8
|
import BigNumber from "bignumber.js";
|
|
17
9
|
var _Web3Number = class extends BigNumber {
|
|
@@ -28,7 +20,6 @@ var _Web3Number = class extends BigNumber {
|
|
|
28
20
|
}
|
|
29
21
|
dividedBy(value) {
|
|
30
22
|
const _value = this.getStandardString(value);
|
|
31
|
-
console.log("dividedBy", _value);
|
|
32
23
|
return this.construct(this.div(_value).toString(), this.decimals);
|
|
33
24
|
}
|
|
34
25
|
plus(value) {
|
|
@@ -46,11 +37,9 @@ var _Web3Number = class extends BigNumber {
|
|
|
46
37
|
return super.toString();
|
|
47
38
|
}
|
|
48
39
|
toJSON() {
|
|
49
|
-
logger.verbose(`converting to json with decimals`);
|
|
50
40
|
return this.toString();
|
|
51
41
|
}
|
|
52
42
|
valueOf() {
|
|
53
|
-
logger.verbose(`converting to valueOf with decimals`);
|
|
54
43
|
return this.toString();
|
|
55
44
|
}
|
|
56
45
|
maxToFixedDecimals() {
|
|
@@ -105,6 +94,14 @@ var ContractAddr = class _ContractAddr {
|
|
|
105
94
|
}
|
|
106
95
|
};
|
|
107
96
|
|
|
97
|
+
// src/utils/logger.browser.ts
|
|
98
|
+
var logger = {
|
|
99
|
+
...console,
|
|
100
|
+
verbose(message) {
|
|
101
|
+
console.log(`[VERBOSE] ${message}`);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
108
105
|
// src/global.ts
|
|
109
106
|
var FatalError = class extends Error {
|
|
110
107
|
constructor(message, err) {
|
|
@@ -18979,14 +18976,24 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
|
|
|
18979
18976
|
_solveExpectedAmountsEq(availableAmount0, availableAmount1, ratio, price) {
|
|
18980
18977
|
const y = ratio.multipliedBy(availableAmount1).minus(availableAmount0).dividedBy(ratio.plus(1 / price));
|
|
18981
18978
|
const x = y.dividedBy(price);
|
|
18979
|
+
logger.verbose(
|
|
18980
|
+
`${_EkuboCLVault.name}: _solveExpectedAmountsEq => x: ${x.toString()}, y: ${y.toString()}, amount0: ${availableAmount0.toString()}, amount1: ${availableAmount1.toString()}`
|
|
18981
|
+
);
|
|
18982
|
+
if (ratio.eq(0)) {
|
|
18983
|
+
return {
|
|
18984
|
+
amount0: Web3Number.fromWei("0", availableAmount0.decimals),
|
|
18985
|
+
amount1: availableAmount1.minus(y),
|
|
18986
|
+
ratio: 0
|
|
18987
|
+
};
|
|
18988
|
+
}
|
|
18982
18989
|
return {
|
|
18983
18990
|
amount0: availableAmount0.plus(x),
|
|
18984
18991
|
amount1: availableAmount1.minus(y),
|
|
18985
18992
|
ratio: Number(ratio.toString())
|
|
18986
18993
|
};
|
|
18987
18994
|
}
|
|
18988
|
-
async
|
|
18989
|
-
const poolKey = await this.getPoolKey();
|
|
18995
|
+
async unusedBalances(_poolKey) {
|
|
18996
|
+
const poolKey = _poolKey || await this.getPoolKey();
|
|
18990
18997
|
const erc20Mod = new ERC20(this.config);
|
|
18991
18998
|
const token0Info = await Global.getTokenInfoFromAddr(poolKey.token0);
|
|
18992
18999
|
const token1Info = await Global.getTokenInfoFromAddr(poolKey.token1);
|
|
@@ -19007,11 +19014,24 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
|
|
|
19007
19014
|
const token1Price = await this.pricer.getPrice(token1Info.symbol);
|
|
19008
19015
|
const token0PriceUsd = token0Price.price * Number(token0Bal1.toFixed(13));
|
|
19009
19016
|
const token1PriceUsd = token1Price.price * Number(token1Bal1.toFixed(13));
|
|
19010
|
-
|
|
19011
|
-
|
|
19012
|
-
|
|
19013
|
-
|
|
19014
|
-
|
|
19017
|
+
return {
|
|
19018
|
+
token0: {
|
|
19019
|
+
amount: token0Bal1,
|
|
19020
|
+
tokenInfo: token0Info,
|
|
19021
|
+
usdValue: token0PriceUsd
|
|
19022
|
+
},
|
|
19023
|
+
token1: {
|
|
19024
|
+
amount: token1Bal1,
|
|
19025
|
+
tokenInfo: token1Info,
|
|
19026
|
+
usdValue: token1PriceUsd
|
|
19027
|
+
}
|
|
19028
|
+
};
|
|
19029
|
+
}
|
|
19030
|
+
async getSwapInfoToHandleUnused(considerRebalance = true) {
|
|
19031
|
+
const poolKey = await this.getPoolKey();
|
|
19032
|
+
const unusedBalances = await this.unusedBalances(poolKey);
|
|
19033
|
+
const { amount: token0Bal1, usdValue: token0PriceUsd } = unusedBalances.token0;
|
|
19034
|
+
const { amount: token1Bal1, usdValue: token1PriceUsd } = unusedBalances.token1;
|
|
19015
19035
|
let token0Bal = token0Bal1;
|
|
19016
19036
|
let token1Bal = token1Bal1;
|
|
19017
19037
|
if (considerRebalance) {
|
|
@@ -19029,25 +19049,33 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
|
|
|
19029
19049
|
logger.verbose(
|
|
19030
19050
|
`${_EkuboCLVault.name}: getSwapInfoToHandleUnused => token0Bal: ${token0Bal.toString()}, token1Bal: ${token1Bal.toString()}`
|
|
19031
19051
|
);
|
|
19032
|
-
|
|
19052
|
+
let ekuboBounds;
|
|
19053
|
+
if (considerRebalance) {
|
|
19054
|
+
ekuboBounds = await this.getNewBounds();
|
|
19055
|
+
} else {
|
|
19056
|
+
ekuboBounds = await this.getCurrentBounds();
|
|
19057
|
+
}
|
|
19033
19058
|
logger.verbose(
|
|
19034
|
-
`${_EkuboCLVault.name}: getSwapInfoToHandleUnused => newBounds: ${
|
|
19059
|
+
`${_EkuboCLVault.name}: getSwapInfoToHandleUnused => newBounds: ${ekuboBounds.lowerTick}, ${ekuboBounds.upperTick}`
|
|
19035
19060
|
);
|
|
19036
19061
|
return await this.getSwapInfoGivenAmounts(
|
|
19037
19062
|
poolKey,
|
|
19038
19063
|
token0Bal,
|
|
19039
19064
|
token1Bal,
|
|
19040
|
-
|
|
19065
|
+
ekuboBounds
|
|
19041
19066
|
);
|
|
19042
19067
|
}
|
|
19043
19068
|
async getSwapInfoGivenAmounts(poolKey, token0Bal, token1Bal, bounds) {
|
|
19069
|
+
logger.verbose(
|
|
19070
|
+
`${_EkuboCLVault.name}: getSwapInfoGivenAmounts::pre => token0Bal: ${token0Bal.toString()}, token1Bal: ${token1Bal.toString()}`
|
|
19071
|
+
);
|
|
19044
19072
|
let expectedAmounts = await this._getExpectedAmountsForLiquidity(
|
|
19045
19073
|
token0Bal,
|
|
19046
19074
|
token1Bal,
|
|
19047
19075
|
bounds
|
|
19048
19076
|
);
|
|
19049
19077
|
logger.verbose(
|
|
19050
|
-
`${_EkuboCLVault.name}: getSwapInfoToHandleUnused =>
|
|
19078
|
+
`${_EkuboCLVault.name}: getSwapInfoToHandleUnused => expectedAmounts2: ${expectedAmounts.amount0.toString()}, ${expectedAmounts.amount1.toString()}`
|
|
19051
19079
|
);
|
|
19052
19080
|
let retry = 0;
|
|
19053
19081
|
const maxRetry = 10;
|
|
@@ -19320,6 +19348,7 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
|
|
|
19320
19348
|
const token0Info = await Global.getTokenInfoFromAddr(poolKey.token0);
|
|
19321
19349
|
const token1Info = await Global.getTokenInfoFromAddr(poolKey.token1);
|
|
19322
19350
|
const bounds = await this.getCurrentBounds();
|
|
19351
|
+
logger.verbose(`${_EkuboCLVault.name}: harvest => unClaimedRewards: ${unClaimedRewards.length}`);
|
|
19323
19352
|
const calls = [];
|
|
19324
19353
|
for (let claim of unClaimedRewards) {
|
|
19325
19354
|
const fee = claim.claim.amount.multipliedBy(this.metadata.additionalInfo.feeBps).dividedBy(1e4);
|
|
@@ -19352,12 +19381,28 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
|
|
|
19352
19381
|
18
|
|
19353
19382
|
// cause its always STRK?
|
|
19354
19383
|
);
|
|
19384
|
+
logger.verbose(
|
|
19385
|
+
`${_EkuboCLVault.name}: harvest => swap1Amount: ${swap1Amount}`
|
|
19386
|
+
);
|
|
19355
19387
|
const remainingAmount = postFeeAmount.minus(swap1Amount);
|
|
19388
|
+
logger.verbose(
|
|
19389
|
+
`${_EkuboCLVault.name}: harvest => remainingAmount: ${remainingAmount}`
|
|
19390
|
+
);
|
|
19356
19391
|
const swapInfo2 = {
|
|
19357
19392
|
...swapInfo,
|
|
19358
19393
|
token_from_amount: uint2564.bnToUint256(remainingAmount.toWei())
|
|
19359
19394
|
};
|
|
19360
19395
|
swapInfo2.token_to_address = token1Info.address.address;
|
|
19396
|
+
logger.verbose(
|
|
19397
|
+
`${_EkuboCLVault.name}: harvest => swapInfo: ${JSON.stringify(
|
|
19398
|
+
swapInfo
|
|
19399
|
+
)}`
|
|
19400
|
+
);
|
|
19401
|
+
logger.verbose(
|
|
19402
|
+
`${_EkuboCLVault.name}: harvest => swapInfo2: ${JSON.stringify(
|
|
19403
|
+
swapInfo2
|
|
19404
|
+
)}`
|
|
19405
|
+
);
|
|
19361
19406
|
const calldata = [
|
|
19362
19407
|
claim.rewardsContract.address,
|
|
19363
19408
|
{
|
package/dist/index.d.ts
CHANGED
|
@@ -672,6 +672,18 @@ declare class EkuboCLVault extends BaseStrategy<DualTokenInfo, DualActionAmount>
|
|
|
672
672
|
*/
|
|
673
673
|
private _getExpectedAmountsForLiquidity;
|
|
674
674
|
private _solveExpectedAmountsEq;
|
|
675
|
+
unusedBalances(_poolKey?: EkuboPoolKey): Promise<{
|
|
676
|
+
token0: {
|
|
677
|
+
amount: Web3Number;
|
|
678
|
+
tokenInfo: TokenInfo;
|
|
679
|
+
usdValue: number;
|
|
680
|
+
};
|
|
681
|
+
token1: {
|
|
682
|
+
amount: Web3Number;
|
|
683
|
+
tokenInfo: TokenInfo;
|
|
684
|
+
usdValue: number;
|
|
685
|
+
};
|
|
686
|
+
}>;
|
|
675
687
|
getSwapInfoToHandleUnused(considerRebalance?: boolean): Promise<SwapInfo>;
|
|
676
688
|
getSwapInfoGivenAmounts(poolKey: EkuboPoolKey, token0Bal: Web3Number, token1Bal: Web3Number, bounds: EkuboBounds): Promise<SwapInfo>;
|
|
677
689
|
/**
|
package/dist/index.js
CHANGED
|
@@ -76,43 +76,6 @@ var import_axios = __toESM(require("axios"));
|
|
|
76
76
|
// src/dataTypes/bignumber.node.ts
|
|
77
77
|
var import_util = __toESM(require("util"));
|
|
78
78
|
|
|
79
|
-
// src/utils/logger.node.ts
|
|
80
|
-
var import_winston = __toESM(require("winston"));
|
|
81
|
-
var colors = {
|
|
82
|
-
error: "red",
|
|
83
|
-
warn: "yellow",
|
|
84
|
-
info: "blue",
|
|
85
|
-
verbose: "white",
|
|
86
|
-
debug: "white"
|
|
87
|
-
};
|
|
88
|
-
import_winston.default.addColors(colors);
|
|
89
|
-
var logger = import_winston.default.createLogger({
|
|
90
|
-
level: "verbose",
|
|
91
|
-
// Set the minimum logging level
|
|
92
|
-
format: import_winston.format.combine(
|
|
93
|
-
import_winston.format.colorize({ all: true }),
|
|
94
|
-
// Apply custom colors
|
|
95
|
-
import_winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }),
|
|
96
|
-
// Add timestamp to log messages
|
|
97
|
-
import_winston.format.printf(({ timestamp, level, message, ...meta }) => {
|
|
98
|
-
let msg = `${timestamp} ${level}: ${message}`;
|
|
99
|
-
if (meta && meta[Symbol.for("splat")]) {
|
|
100
|
-
for (const arg of meta[Symbol.for("splat")]) {
|
|
101
|
-
if (arg instanceof Error) {
|
|
102
|
-
msg += `
|
|
103
|
-
${arg.stack}`;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
return msg;
|
|
108
|
-
})
|
|
109
|
-
),
|
|
110
|
-
transports: [
|
|
111
|
-
new import_winston.default.transports.Console()
|
|
112
|
-
// Output logs to the console
|
|
113
|
-
]
|
|
114
|
-
});
|
|
115
|
-
|
|
116
79
|
// src/dataTypes/_bignumber.ts
|
|
117
80
|
var import_bignumber = __toESM(require("bignumber.js"));
|
|
118
81
|
var _Web3Number = class extends import_bignumber.default {
|
|
@@ -129,7 +92,6 @@ var _Web3Number = class extends import_bignumber.default {
|
|
|
129
92
|
}
|
|
130
93
|
dividedBy(value) {
|
|
131
94
|
const _value = this.getStandardString(value);
|
|
132
|
-
console.log("dividedBy", _value);
|
|
133
95
|
return this.construct(this.div(_value).toString(), this.decimals);
|
|
134
96
|
}
|
|
135
97
|
plus(value) {
|
|
@@ -147,11 +109,9 @@ var _Web3Number = class extends import_bignumber.default {
|
|
|
147
109
|
return super.toString();
|
|
148
110
|
}
|
|
149
111
|
toJSON() {
|
|
150
|
-
logger.verbose(`converting to json with decimals`);
|
|
151
112
|
return this.toString();
|
|
152
113
|
}
|
|
153
114
|
valueOf() {
|
|
154
|
-
logger.verbose(`converting to valueOf with decimals`);
|
|
155
115
|
return this.toString();
|
|
156
116
|
}
|
|
157
117
|
maxToFixedDecimals() {
|
|
@@ -215,6 +175,43 @@ var ContractAddr = class _ContractAddr {
|
|
|
215
175
|
}
|
|
216
176
|
};
|
|
217
177
|
|
|
178
|
+
// src/utils/logger.node.ts
|
|
179
|
+
var import_winston = __toESM(require("winston"));
|
|
180
|
+
var colors = {
|
|
181
|
+
error: "red",
|
|
182
|
+
warn: "yellow",
|
|
183
|
+
info: "blue",
|
|
184
|
+
verbose: "white",
|
|
185
|
+
debug: "white"
|
|
186
|
+
};
|
|
187
|
+
import_winston.default.addColors(colors);
|
|
188
|
+
var logger = import_winston.default.createLogger({
|
|
189
|
+
level: "verbose",
|
|
190
|
+
// Set the minimum logging level
|
|
191
|
+
format: import_winston.format.combine(
|
|
192
|
+
import_winston.format.colorize({ all: true }),
|
|
193
|
+
// Apply custom colors
|
|
194
|
+
import_winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }),
|
|
195
|
+
// Add timestamp to log messages
|
|
196
|
+
import_winston.format.printf(({ timestamp, level, message, ...meta }) => {
|
|
197
|
+
let msg = `${timestamp} ${level}: ${message}`;
|
|
198
|
+
if (meta && meta[Symbol.for("splat")]) {
|
|
199
|
+
for (const arg of meta[Symbol.for("splat")]) {
|
|
200
|
+
if (arg instanceof Error) {
|
|
201
|
+
msg += `
|
|
202
|
+
${arg.stack}`;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return msg;
|
|
207
|
+
})
|
|
208
|
+
),
|
|
209
|
+
transports: [
|
|
210
|
+
new import_winston.default.transports.Console()
|
|
211
|
+
// Output logs to the console
|
|
212
|
+
]
|
|
213
|
+
});
|
|
214
|
+
|
|
218
215
|
// src/global.ts
|
|
219
216
|
var FatalError = class extends Error {
|
|
220
217
|
constructor(message, err) {
|
|
@@ -19093,14 +19090,24 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
|
|
|
19093
19090
|
_solveExpectedAmountsEq(availableAmount0, availableAmount1, ratio, price) {
|
|
19094
19091
|
const y = ratio.multipliedBy(availableAmount1).minus(availableAmount0).dividedBy(ratio.plus(1 / price));
|
|
19095
19092
|
const x = y.dividedBy(price);
|
|
19093
|
+
logger.verbose(
|
|
19094
|
+
`${_EkuboCLVault.name}: _solveExpectedAmountsEq => x: ${x.toString()}, y: ${y.toString()}, amount0: ${availableAmount0.toString()}, amount1: ${availableAmount1.toString()}`
|
|
19095
|
+
);
|
|
19096
|
+
if (ratio.eq(0)) {
|
|
19097
|
+
return {
|
|
19098
|
+
amount0: Web3Number.fromWei("0", availableAmount0.decimals),
|
|
19099
|
+
amount1: availableAmount1.minus(y),
|
|
19100
|
+
ratio: 0
|
|
19101
|
+
};
|
|
19102
|
+
}
|
|
19096
19103
|
return {
|
|
19097
19104
|
amount0: availableAmount0.plus(x),
|
|
19098
19105
|
amount1: availableAmount1.minus(y),
|
|
19099
19106
|
ratio: Number(ratio.toString())
|
|
19100
19107
|
};
|
|
19101
19108
|
}
|
|
19102
|
-
async
|
|
19103
|
-
const poolKey = await this.getPoolKey();
|
|
19109
|
+
async unusedBalances(_poolKey) {
|
|
19110
|
+
const poolKey = _poolKey || await this.getPoolKey();
|
|
19104
19111
|
const erc20Mod = new ERC20(this.config);
|
|
19105
19112
|
const token0Info = await Global.getTokenInfoFromAddr(poolKey.token0);
|
|
19106
19113
|
const token1Info = await Global.getTokenInfoFromAddr(poolKey.token1);
|
|
@@ -19121,11 +19128,24 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
|
|
|
19121
19128
|
const token1Price = await this.pricer.getPrice(token1Info.symbol);
|
|
19122
19129
|
const token0PriceUsd = token0Price.price * Number(token0Bal1.toFixed(13));
|
|
19123
19130
|
const token1PriceUsd = token1Price.price * Number(token1Bal1.toFixed(13));
|
|
19124
|
-
|
|
19125
|
-
|
|
19126
|
-
|
|
19127
|
-
|
|
19128
|
-
|
|
19131
|
+
return {
|
|
19132
|
+
token0: {
|
|
19133
|
+
amount: token0Bal1,
|
|
19134
|
+
tokenInfo: token0Info,
|
|
19135
|
+
usdValue: token0PriceUsd
|
|
19136
|
+
},
|
|
19137
|
+
token1: {
|
|
19138
|
+
amount: token1Bal1,
|
|
19139
|
+
tokenInfo: token1Info,
|
|
19140
|
+
usdValue: token1PriceUsd
|
|
19141
|
+
}
|
|
19142
|
+
};
|
|
19143
|
+
}
|
|
19144
|
+
async getSwapInfoToHandleUnused(considerRebalance = true) {
|
|
19145
|
+
const poolKey = await this.getPoolKey();
|
|
19146
|
+
const unusedBalances = await this.unusedBalances(poolKey);
|
|
19147
|
+
const { amount: token0Bal1, usdValue: token0PriceUsd } = unusedBalances.token0;
|
|
19148
|
+
const { amount: token1Bal1, usdValue: token1PriceUsd } = unusedBalances.token1;
|
|
19129
19149
|
let token0Bal = token0Bal1;
|
|
19130
19150
|
let token1Bal = token1Bal1;
|
|
19131
19151
|
if (considerRebalance) {
|
|
@@ -19143,25 +19163,33 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
|
|
|
19143
19163
|
logger.verbose(
|
|
19144
19164
|
`${_EkuboCLVault.name}: getSwapInfoToHandleUnused => token0Bal: ${token0Bal.toString()}, token1Bal: ${token1Bal.toString()}`
|
|
19145
19165
|
);
|
|
19146
|
-
|
|
19166
|
+
let ekuboBounds;
|
|
19167
|
+
if (considerRebalance) {
|
|
19168
|
+
ekuboBounds = await this.getNewBounds();
|
|
19169
|
+
} else {
|
|
19170
|
+
ekuboBounds = await this.getCurrentBounds();
|
|
19171
|
+
}
|
|
19147
19172
|
logger.verbose(
|
|
19148
|
-
`${_EkuboCLVault.name}: getSwapInfoToHandleUnused => newBounds: ${
|
|
19173
|
+
`${_EkuboCLVault.name}: getSwapInfoToHandleUnused => newBounds: ${ekuboBounds.lowerTick}, ${ekuboBounds.upperTick}`
|
|
19149
19174
|
);
|
|
19150
19175
|
return await this.getSwapInfoGivenAmounts(
|
|
19151
19176
|
poolKey,
|
|
19152
19177
|
token0Bal,
|
|
19153
19178
|
token1Bal,
|
|
19154
|
-
|
|
19179
|
+
ekuboBounds
|
|
19155
19180
|
);
|
|
19156
19181
|
}
|
|
19157
19182
|
async getSwapInfoGivenAmounts(poolKey, token0Bal, token1Bal, bounds) {
|
|
19183
|
+
logger.verbose(
|
|
19184
|
+
`${_EkuboCLVault.name}: getSwapInfoGivenAmounts::pre => token0Bal: ${token0Bal.toString()}, token1Bal: ${token1Bal.toString()}`
|
|
19185
|
+
);
|
|
19158
19186
|
let expectedAmounts = await this._getExpectedAmountsForLiquidity(
|
|
19159
19187
|
token0Bal,
|
|
19160
19188
|
token1Bal,
|
|
19161
19189
|
bounds
|
|
19162
19190
|
);
|
|
19163
19191
|
logger.verbose(
|
|
19164
|
-
`${_EkuboCLVault.name}: getSwapInfoToHandleUnused =>
|
|
19192
|
+
`${_EkuboCLVault.name}: getSwapInfoToHandleUnused => expectedAmounts2: ${expectedAmounts.amount0.toString()}, ${expectedAmounts.amount1.toString()}`
|
|
19165
19193
|
);
|
|
19166
19194
|
let retry = 0;
|
|
19167
19195
|
const maxRetry = 10;
|
|
@@ -19434,6 +19462,7 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
|
|
|
19434
19462
|
const token0Info = await Global.getTokenInfoFromAddr(poolKey.token0);
|
|
19435
19463
|
const token1Info = await Global.getTokenInfoFromAddr(poolKey.token1);
|
|
19436
19464
|
const bounds = await this.getCurrentBounds();
|
|
19465
|
+
logger.verbose(`${_EkuboCLVault.name}: harvest => unClaimedRewards: ${unClaimedRewards.length}`);
|
|
19437
19466
|
const calls = [];
|
|
19438
19467
|
for (let claim of unClaimedRewards) {
|
|
19439
19468
|
const fee = claim.claim.amount.multipliedBy(this.metadata.additionalInfo.feeBps).dividedBy(1e4);
|
|
@@ -19466,12 +19495,28 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
|
|
|
19466
19495
|
18
|
|
19467
19496
|
// cause its always STRK?
|
|
19468
19497
|
);
|
|
19498
|
+
logger.verbose(
|
|
19499
|
+
`${_EkuboCLVault.name}: harvest => swap1Amount: ${swap1Amount}`
|
|
19500
|
+
);
|
|
19469
19501
|
const remainingAmount = postFeeAmount.minus(swap1Amount);
|
|
19502
|
+
logger.verbose(
|
|
19503
|
+
`${_EkuboCLVault.name}: harvest => remainingAmount: ${remainingAmount}`
|
|
19504
|
+
);
|
|
19470
19505
|
const swapInfo2 = {
|
|
19471
19506
|
...swapInfo,
|
|
19472
19507
|
token_from_amount: import_starknet9.uint256.bnToUint256(remainingAmount.toWei())
|
|
19473
19508
|
};
|
|
19474
19509
|
swapInfo2.token_to_address = token1Info.address.address;
|
|
19510
|
+
logger.verbose(
|
|
19511
|
+
`${_EkuboCLVault.name}: harvest => swapInfo: ${JSON.stringify(
|
|
19512
|
+
swapInfo
|
|
19513
|
+
)}`
|
|
19514
|
+
);
|
|
19515
|
+
logger.verbose(
|
|
19516
|
+
`${_EkuboCLVault.name}: harvest => swapInfo2: ${JSON.stringify(
|
|
19517
|
+
swapInfo2
|
|
19518
|
+
)}`
|
|
19519
|
+
);
|
|
19475
19520
|
const calldata = [
|
|
19476
19521
|
claim.rewardsContract.address,
|
|
19477
19522
|
{
|
package/dist/index.mjs
CHANGED
|
@@ -7,43 +7,6 @@ import axios from "axios";
|
|
|
7
7
|
// src/dataTypes/bignumber.node.ts
|
|
8
8
|
import util from "util";
|
|
9
9
|
|
|
10
|
-
// src/utils/logger.node.ts
|
|
11
|
-
import winston, { format } from "winston";
|
|
12
|
-
var colors = {
|
|
13
|
-
error: "red",
|
|
14
|
-
warn: "yellow",
|
|
15
|
-
info: "blue",
|
|
16
|
-
verbose: "white",
|
|
17
|
-
debug: "white"
|
|
18
|
-
};
|
|
19
|
-
winston.addColors(colors);
|
|
20
|
-
var logger = winston.createLogger({
|
|
21
|
-
level: "verbose",
|
|
22
|
-
// Set the minimum logging level
|
|
23
|
-
format: format.combine(
|
|
24
|
-
format.colorize({ all: true }),
|
|
25
|
-
// Apply custom colors
|
|
26
|
-
format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }),
|
|
27
|
-
// Add timestamp to log messages
|
|
28
|
-
format.printf(({ timestamp, level, message, ...meta }) => {
|
|
29
|
-
let msg = `${timestamp} ${level}: ${message}`;
|
|
30
|
-
if (meta && meta[Symbol.for("splat")]) {
|
|
31
|
-
for (const arg of meta[Symbol.for("splat")]) {
|
|
32
|
-
if (arg instanceof Error) {
|
|
33
|
-
msg += `
|
|
34
|
-
${arg.stack}`;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return msg;
|
|
39
|
-
})
|
|
40
|
-
),
|
|
41
|
-
transports: [
|
|
42
|
-
new winston.transports.Console()
|
|
43
|
-
// Output logs to the console
|
|
44
|
-
]
|
|
45
|
-
});
|
|
46
|
-
|
|
47
10
|
// src/dataTypes/_bignumber.ts
|
|
48
11
|
import BigNumber from "bignumber.js";
|
|
49
12
|
var _Web3Number = class extends BigNumber {
|
|
@@ -60,7 +23,6 @@ var _Web3Number = class extends BigNumber {
|
|
|
60
23
|
}
|
|
61
24
|
dividedBy(value) {
|
|
62
25
|
const _value = this.getStandardString(value);
|
|
63
|
-
console.log("dividedBy", _value);
|
|
64
26
|
return this.construct(this.div(_value).toString(), this.decimals);
|
|
65
27
|
}
|
|
66
28
|
plus(value) {
|
|
@@ -78,11 +40,9 @@ var _Web3Number = class extends BigNumber {
|
|
|
78
40
|
return super.toString();
|
|
79
41
|
}
|
|
80
42
|
toJSON() {
|
|
81
|
-
logger.verbose(`converting to json with decimals`);
|
|
82
43
|
return this.toString();
|
|
83
44
|
}
|
|
84
45
|
valueOf() {
|
|
85
|
-
logger.verbose(`converting to valueOf with decimals`);
|
|
86
46
|
return this.toString();
|
|
87
47
|
}
|
|
88
48
|
maxToFixedDecimals() {
|
|
@@ -146,6 +106,43 @@ var ContractAddr = class _ContractAddr {
|
|
|
146
106
|
}
|
|
147
107
|
};
|
|
148
108
|
|
|
109
|
+
// src/utils/logger.node.ts
|
|
110
|
+
import winston, { format } from "winston";
|
|
111
|
+
var colors = {
|
|
112
|
+
error: "red",
|
|
113
|
+
warn: "yellow",
|
|
114
|
+
info: "blue",
|
|
115
|
+
verbose: "white",
|
|
116
|
+
debug: "white"
|
|
117
|
+
};
|
|
118
|
+
winston.addColors(colors);
|
|
119
|
+
var logger = winston.createLogger({
|
|
120
|
+
level: "verbose",
|
|
121
|
+
// Set the minimum logging level
|
|
122
|
+
format: format.combine(
|
|
123
|
+
format.colorize({ all: true }),
|
|
124
|
+
// Apply custom colors
|
|
125
|
+
format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }),
|
|
126
|
+
// Add timestamp to log messages
|
|
127
|
+
format.printf(({ timestamp, level, message, ...meta }) => {
|
|
128
|
+
let msg = `${timestamp} ${level}: ${message}`;
|
|
129
|
+
if (meta && meta[Symbol.for("splat")]) {
|
|
130
|
+
for (const arg of meta[Symbol.for("splat")]) {
|
|
131
|
+
if (arg instanceof Error) {
|
|
132
|
+
msg += `
|
|
133
|
+
${arg.stack}`;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return msg;
|
|
138
|
+
})
|
|
139
|
+
),
|
|
140
|
+
transports: [
|
|
141
|
+
new winston.transports.Console()
|
|
142
|
+
// Output logs to the console
|
|
143
|
+
]
|
|
144
|
+
});
|
|
145
|
+
|
|
149
146
|
// src/global.ts
|
|
150
147
|
var FatalError = class extends Error {
|
|
151
148
|
constructor(message, err) {
|
|
@@ -19028,14 +19025,24 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
|
|
|
19028
19025
|
_solveExpectedAmountsEq(availableAmount0, availableAmount1, ratio, price) {
|
|
19029
19026
|
const y = ratio.multipliedBy(availableAmount1).minus(availableAmount0).dividedBy(ratio.plus(1 / price));
|
|
19030
19027
|
const x = y.dividedBy(price);
|
|
19028
|
+
logger.verbose(
|
|
19029
|
+
`${_EkuboCLVault.name}: _solveExpectedAmountsEq => x: ${x.toString()}, y: ${y.toString()}, amount0: ${availableAmount0.toString()}, amount1: ${availableAmount1.toString()}`
|
|
19030
|
+
);
|
|
19031
|
+
if (ratio.eq(0)) {
|
|
19032
|
+
return {
|
|
19033
|
+
amount0: Web3Number.fromWei("0", availableAmount0.decimals),
|
|
19034
|
+
amount1: availableAmount1.minus(y),
|
|
19035
|
+
ratio: 0
|
|
19036
|
+
};
|
|
19037
|
+
}
|
|
19031
19038
|
return {
|
|
19032
19039
|
amount0: availableAmount0.plus(x),
|
|
19033
19040
|
amount1: availableAmount1.minus(y),
|
|
19034
19041
|
ratio: Number(ratio.toString())
|
|
19035
19042
|
};
|
|
19036
19043
|
}
|
|
19037
|
-
async
|
|
19038
|
-
const poolKey = await this.getPoolKey();
|
|
19044
|
+
async unusedBalances(_poolKey) {
|
|
19045
|
+
const poolKey = _poolKey || await this.getPoolKey();
|
|
19039
19046
|
const erc20Mod = new ERC20(this.config);
|
|
19040
19047
|
const token0Info = await Global.getTokenInfoFromAddr(poolKey.token0);
|
|
19041
19048
|
const token1Info = await Global.getTokenInfoFromAddr(poolKey.token1);
|
|
@@ -19056,11 +19063,24 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
|
|
|
19056
19063
|
const token1Price = await this.pricer.getPrice(token1Info.symbol);
|
|
19057
19064
|
const token0PriceUsd = token0Price.price * Number(token0Bal1.toFixed(13));
|
|
19058
19065
|
const token1PriceUsd = token1Price.price * Number(token1Bal1.toFixed(13));
|
|
19059
|
-
|
|
19060
|
-
|
|
19061
|
-
|
|
19062
|
-
|
|
19063
|
-
|
|
19066
|
+
return {
|
|
19067
|
+
token0: {
|
|
19068
|
+
amount: token0Bal1,
|
|
19069
|
+
tokenInfo: token0Info,
|
|
19070
|
+
usdValue: token0PriceUsd
|
|
19071
|
+
},
|
|
19072
|
+
token1: {
|
|
19073
|
+
amount: token1Bal1,
|
|
19074
|
+
tokenInfo: token1Info,
|
|
19075
|
+
usdValue: token1PriceUsd
|
|
19076
|
+
}
|
|
19077
|
+
};
|
|
19078
|
+
}
|
|
19079
|
+
async getSwapInfoToHandleUnused(considerRebalance = true) {
|
|
19080
|
+
const poolKey = await this.getPoolKey();
|
|
19081
|
+
const unusedBalances = await this.unusedBalances(poolKey);
|
|
19082
|
+
const { amount: token0Bal1, usdValue: token0PriceUsd } = unusedBalances.token0;
|
|
19083
|
+
const { amount: token1Bal1, usdValue: token1PriceUsd } = unusedBalances.token1;
|
|
19064
19084
|
let token0Bal = token0Bal1;
|
|
19065
19085
|
let token1Bal = token1Bal1;
|
|
19066
19086
|
if (considerRebalance) {
|
|
@@ -19078,25 +19098,33 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
|
|
|
19078
19098
|
logger.verbose(
|
|
19079
19099
|
`${_EkuboCLVault.name}: getSwapInfoToHandleUnused => token0Bal: ${token0Bal.toString()}, token1Bal: ${token1Bal.toString()}`
|
|
19080
19100
|
);
|
|
19081
|
-
|
|
19101
|
+
let ekuboBounds;
|
|
19102
|
+
if (considerRebalance) {
|
|
19103
|
+
ekuboBounds = await this.getNewBounds();
|
|
19104
|
+
} else {
|
|
19105
|
+
ekuboBounds = await this.getCurrentBounds();
|
|
19106
|
+
}
|
|
19082
19107
|
logger.verbose(
|
|
19083
|
-
`${_EkuboCLVault.name}: getSwapInfoToHandleUnused => newBounds: ${
|
|
19108
|
+
`${_EkuboCLVault.name}: getSwapInfoToHandleUnused => newBounds: ${ekuboBounds.lowerTick}, ${ekuboBounds.upperTick}`
|
|
19084
19109
|
);
|
|
19085
19110
|
return await this.getSwapInfoGivenAmounts(
|
|
19086
19111
|
poolKey,
|
|
19087
19112
|
token0Bal,
|
|
19088
19113
|
token1Bal,
|
|
19089
|
-
|
|
19114
|
+
ekuboBounds
|
|
19090
19115
|
);
|
|
19091
19116
|
}
|
|
19092
19117
|
async getSwapInfoGivenAmounts(poolKey, token0Bal, token1Bal, bounds) {
|
|
19118
|
+
logger.verbose(
|
|
19119
|
+
`${_EkuboCLVault.name}: getSwapInfoGivenAmounts::pre => token0Bal: ${token0Bal.toString()}, token1Bal: ${token1Bal.toString()}`
|
|
19120
|
+
);
|
|
19093
19121
|
let expectedAmounts = await this._getExpectedAmountsForLiquidity(
|
|
19094
19122
|
token0Bal,
|
|
19095
19123
|
token1Bal,
|
|
19096
19124
|
bounds
|
|
19097
19125
|
);
|
|
19098
19126
|
logger.verbose(
|
|
19099
|
-
`${_EkuboCLVault.name}: getSwapInfoToHandleUnused =>
|
|
19127
|
+
`${_EkuboCLVault.name}: getSwapInfoToHandleUnused => expectedAmounts2: ${expectedAmounts.amount0.toString()}, ${expectedAmounts.amount1.toString()}`
|
|
19100
19128
|
);
|
|
19101
19129
|
let retry = 0;
|
|
19102
19130
|
const maxRetry = 10;
|
|
@@ -19369,6 +19397,7 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
|
|
|
19369
19397
|
const token0Info = await Global.getTokenInfoFromAddr(poolKey.token0);
|
|
19370
19398
|
const token1Info = await Global.getTokenInfoFromAddr(poolKey.token1);
|
|
19371
19399
|
const bounds = await this.getCurrentBounds();
|
|
19400
|
+
logger.verbose(`${_EkuboCLVault.name}: harvest => unClaimedRewards: ${unClaimedRewards.length}`);
|
|
19372
19401
|
const calls = [];
|
|
19373
19402
|
for (let claim of unClaimedRewards) {
|
|
19374
19403
|
const fee = claim.claim.amount.multipliedBy(this.metadata.additionalInfo.feeBps).dividedBy(1e4);
|
|
@@ -19401,12 +19430,28 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
|
|
|
19401
19430
|
18
|
|
19402
19431
|
// cause its always STRK?
|
|
19403
19432
|
);
|
|
19433
|
+
logger.verbose(
|
|
19434
|
+
`${_EkuboCLVault.name}: harvest => swap1Amount: ${swap1Amount}`
|
|
19435
|
+
);
|
|
19404
19436
|
const remainingAmount = postFeeAmount.minus(swap1Amount);
|
|
19437
|
+
logger.verbose(
|
|
19438
|
+
`${_EkuboCLVault.name}: harvest => remainingAmount: ${remainingAmount}`
|
|
19439
|
+
);
|
|
19405
19440
|
const swapInfo2 = {
|
|
19406
19441
|
...swapInfo,
|
|
19407
19442
|
token_from_amount: uint2564.bnToUint256(remainingAmount.toWei())
|
|
19408
19443
|
};
|
|
19409
19444
|
swapInfo2.token_to_address = token1Info.address.address;
|
|
19445
|
+
logger.verbose(
|
|
19446
|
+
`${_EkuboCLVault.name}: harvest => swapInfo: ${JSON.stringify(
|
|
19447
|
+
swapInfo
|
|
19448
|
+
)}`
|
|
19449
|
+
);
|
|
19450
|
+
logger.verbose(
|
|
19451
|
+
`${_EkuboCLVault.name}: harvest => swapInfo2: ${JSON.stringify(
|
|
19452
|
+
swapInfo2
|
|
19453
|
+
)}`
|
|
19454
|
+
);
|
|
19410
19455
|
const calldata = [
|
|
19411
19456
|
claim.rewardsContract.address,
|
|
19412
19457
|
{
|
package/package.json
CHANGED
|
@@ -795,6 +795,7 @@ export class EkuboCLVault extends BaseStrategy<
|
|
|
795
795
|
ratio: Web3Number,
|
|
796
796
|
price: number
|
|
797
797
|
) {
|
|
798
|
+
|
|
798
799
|
// (amount0 + x) / (amount1 - y) = ratio
|
|
799
800
|
// x = y * Py / Px ---- (1)
|
|
800
801
|
// => (amount0 + y * Py / Px) / (amount1 - y) = ratio
|
|
@@ -807,6 +808,17 @@ export class EkuboCLVault extends BaseStrategy<
|
|
|
807
808
|
.minus(availableAmount0)
|
|
808
809
|
.dividedBy(ratio.plus(1 / price));
|
|
809
810
|
const x = y.dividedBy(price);
|
|
811
|
+
logger.verbose(
|
|
812
|
+
`${EkuboCLVault.name}: _solveExpectedAmountsEq => x: ${x.toString()}, y: ${y.toString()}, amount0: ${availableAmount0.toString()}, amount1: ${availableAmount1.toString()}`
|
|
813
|
+
);
|
|
814
|
+
|
|
815
|
+
if (ratio.eq(0)) {
|
|
816
|
+
return {
|
|
817
|
+
amount0: Web3Number.fromWei("0", availableAmount0.decimals),
|
|
818
|
+
amount1: availableAmount1.minus(y),
|
|
819
|
+
ratio: 0,
|
|
820
|
+
};
|
|
821
|
+
}
|
|
810
822
|
return {
|
|
811
823
|
amount0: availableAmount0.plus(x),
|
|
812
824
|
amount1: availableAmount1.minus(y),
|
|
@@ -814,10 +826,8 @@ export class EkuboCLVault extends BaseStrategy<
|
|
|
814
826
|
};
|
|
815
827
|
}
|
|
816
828
|
|
|
817
|
-
async
|
|
818
|
-
const poolKey = await this.getPoolKey();
|
|
819
|
-
|
|
820
|
-
// fetch current unused balances of vault
|
|
829
|
+
async unusedBalances(_poolKey?: EkuboPoolKey) {
|
|
830
|
+
const poolKey = _poolKey || (await this.getPoolKey());
|
|
821
831
|
const erc20Mod = new ERC20(this.config);
|
|
822
832
|
const token0Info = await Global.getTokenInfoFromAddr(poolKey.token0);
|
|
823
833
|
const token1Info = await Global.getTokenInfoFromAddr(poolKey.token1);
|
|
@@ -831,6 +841,7 @@ export class EkuboCLVault extends BaseStrategy<
|
|
|
831
841
|
this.address.address,
|
|
832
842
|
token1Info.decimals
|
|
833
843
|
);
|
|
844
|
+
|
|
834
845
|
logger.verbose(
|
|
835
846
|
`${
|
|
836
847
|
EkuboCLVault.name
|
|
@@ -841,16 +852,39 @@ export class EkuboCLVault extends BaseStrategy<
|
|
|
841
852
|
const token1Price = await this.pricer.getPrice(token1Info.symbol);
|
|
842
853
|
const token0PriceUsd = token0Price.price * Number(token0Bal1.toFixed(13));
|
|
843
854
|
const token1PriceUsd = token1Price.price * Number(token1Bal1.toFixed(13));
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
855
|
+
|
|
856
|
+
return {
|
|
857
|
+
token0: {
|
|
858
|
+
amount: token0Bal1,
|
|
859
|
+
tokenInfo: token0Info,
|
|
860
|
+
usdValue: token0PriceUsd,
|
|
861
|
+
},
|
|
862
|
+
token1: {
|
|
863
|
+
amount: token1Bal1,
|
|
864
|
+
tokenInfo: token1Info,
|
|
865
|
+
usdValue: token1PriceUsd,
|
|
866
|
+
},
|
|
853
867
|
}
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
async getSwapInfoToHandleUnused(considerRebalance: boolean = true) {
|
|
871
|
+
const poolKey = await this.getPoolKey();
|
|
872
|
+
|
|
873
|
+
// fetch current unused balances of vault
|
|
874
|
+
const unusedBalances = await this.unusedBalances(poolKey);
|
|
875
|
+
const { amount: token0Bal1, usdValue: token0PriceUsd} = unusedBalances.token0;
|
|
876
|
+
const { amount: token1Bal1, usdValue: token1PriceUsd} = unusedBalances.token1;
|
|
877
|
+
|
|
878
|
+
// if (token0PriceUsd > 1 && token1PriceUsd > 1) {
|
|
879
|
+
// // the swap is designed to handle one token only.
|
|
880
|
+
// // i.e. all balance should be in one token
|
|
881
|
+
// // except small amount of dust
|
|
882
|
+
// // so we need to call handle_fees first, which will atleast use
|
|
883
|
+
// // most of one token
|
|
884
|
+
// throw new Error(
|
|
885
|
+
// "Both tokens are non-zero and above $1, call handle_fees first"
|
|
886
|
+
// );
|
|
887
|
+
// }
|
|
854
888
|
|
|
855
889
|
let token0Bal = token0Bal1;
|
|
856
890
|
let token1Bal = token1Bal1;
|
|
@@ -875,16 +909,21 @@ export class EkuboCLVault extends BaseStrategy<
|
|
|
875
909
|
);
|
|
876
910
|
|
|
877
911
|
// get expected amounts for liquidity
|
|
878
|
-
|
|
912
|
+
let ekuboBounds: EkuboBounds;
|
|
913
|
+
if (considerRebalance) {
|
|
914
|
+
ekuboBounds = await this.getNewBounds();
|
|
915
|
+
} else {
|
|
916
|
+
ekuboBounds = await this.getCurrentBounds();
|
|
917
|
+
}
|
|
879
918
|
logger.verbose(
|
|
880
|
-
`${EkuboCLVault.name}: getSwapInfoToHandleUnused => newBounds: ${
|
|
919
|
+
`${EkuboCLVault.name}: getSwapInfoToHandleUnused => newBounds: ${ekuboBounds.lowerTick}, ${ekuboBounds.upperTick}`
|
|
881
920
|
);
|
|
882
921
|
|
|
883
922
|
return await this.getSwapInfoGivenAmounts(
|
|
884
923
|
poolKey,
|
|
885
924
|
token0Bal,
|
|
886
925
|
token1Bal,
|
|
887
|
-
|
|
926
|
+
ekuboBounds
|
|
888
927
|
);
|
|
889
928
|
}
|
|
890
929
|
|
|
@@ -894,6 +933,9 @@ export class EkuboCLVault extends BaseStrategy<
|
|
|
894
933
|
token1Bal: Web3Number,
|
|
895
934
|
bounds: EkuboBounds
|
|
896
935
|
): Promise<SwapInfo> {
|
|
936
|
+
logger.verbose(
|
|
937
|
+
`${EkuboCLVault.name}: getSwapInfoGivenAmounts::pre => token0Bal: ${token0Bal.toString()}, token1Bal: ${token1Bal.toString()}`
|
|
938
|
+
);
|
|
897
939
|
let expectedAmounts = await this._getExpectedAmountsForLiquidity(
|
|
898
940
|
token0Bal,
|
|
899
941
|
token1Bal,
|
|
@@ -902,7 +944,7 @@ export class EkuboCLVault extends BaseStrategy<
|
|
|
902
944
|
logger.verbose(
|
|
903
945
|
`${
|
|
904
946
|
EkuboCLVault.name
|
|
905
|
-
}: getSwapInfoToHandleUnused =>
|
|
947
|
+
}: getSwapInfoToHandleUnused => expectedAmounts2: ${expectedAmounts.amount0.toString()}, ${expectedAmounts.amount1.toString()}`
|
|
906
948
|
);
|
|
907
949
|
|
|
908
950
|
// get swap info
|
|
@@ -1266,6 +1308,7 @@ export class EkuboCLVault extends BaseStrategy<
|
|
|
1266
1308
|
const token0Info = await Global.getTokenInfoFromAddr(poolKey.token0);
|
|
1267
1309
|
const token1Info = await Global.getTokenInfoFromAddr(poolKey.token1);
|
|
1268
1310
|
const bounds = await this.getCurrentBounds();
|
|
1311
|
+
logger.verbose(`${EkuboCLVault.name}: harvest => unClaimedRewards: ${unClaimedRewards.length}`);
|
|
1269
1312
|
const calls: Call[] = [];
|
|
1270
1313
|
for (let claim of unClaimedRewards) {
|
|
1271
1314
|
const fee = claim.claim.amount
|
|
@@ -1279,6 +1322,8 @@ export class EkuboCLVault extends BaseStrategy<
|
|
|
1279
1322
|
EkuboCLVault.name
|
|
1280
1323
|
}: harvest => Processing claim, isToken1: ${isToken1} amount: ${postFeeAmount.toWei()}`
|
|
1281
1324
|
);
|
|
1325
|
+
|
|
1326
|
+
// todo what if the claim token is neither token0 or token1
|
|
1282
1327
|
const token0Amt = isToken1
|
|
1283
1328
|
? new Web3Number(0, token0Info.decimals)
|
|
1284
1329
|
: postFeeAmount;
|
|
@@ -1310,12 +1355,28 @@ export class EkuboCLVault extends BaseStrategy<
|
|
|
1310
1355
|
uint256.uint256ToBN(swapInfo1.token_from_amount).toString(),
|
|
1311
1356
|
18, // cause its always STRK?
|
|
1312
1357
|
);
|
|
1358
|
+
logger.verbose(
|
|
1359
|
+
`${EkuboCLVault.name}: harvest => swap1Amount: ${swap1Amount}`
|
|
1360
|
+
);
|
|
1313
1361
|
const remainingAmount = postFeeAmount.minus(swap1Amount);
|
|
1362
|
+
logger.verbose(
|
|
1363
|
+
`${EkuboCLVault.name}: harvest => remainingAmount: ${remainingAmount}`
|
|
1364
|
+
);
|
|
1314
1365
|
const swapInfo2 = {
|
|
1315
1366
|
...swapInfo,
|
|
1316
1367
|
token_from_amount: uint256.bnToUint256(remainingAmount.toWei()),
|
|
1317
1368
|
};
|
|
1318
1369
|
swapInfo2.token_to_address = token1Info.address.address;
|
|
1370
|
+
logger.verbose(
|
|
1371
|
+
`${EkuboCLVault.name}: harvest => swapInfo: ${JSON.stringify(
|
|
1372
|
+
swapInfo
|
|
1373
|
+
)}`
|
|
1374
|
+
);
|
|
1375
|
+
logger.verbose(
|
|
1376
|
+
`${EkuboCLVault.name}: harvest => swapInfo2: ${JSON.stringify(
|
|
1377
|
+
swapInfo2
|
|
1378
|
+
)}`
|
|
1379
|
+
);
|
|
1319
1380
|
const calldata = [
|
|
1320
1381
|
claim.rewardsContract.address,
|
|
1321
1382
|
{
|