@strkfarm/sdk 1.0.32 → 1.0.34
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/cli.js +7 -7
- package/dist/cli.mjs +7 -7
- package/dist/index.browser.global.js +7990 -15538
- package/dist/index.browser.mjs +60 -30
- package/dist/index.d.ts +1 -1
- package/dist/index.js +60 -30
- package/dist/index.mjs +60 -30
- package/package.json +1 -1
- package/src/global.ts +7 -7
- package/src/strategies/ekubo-cl-vault.tsx +55 -32
package/dist/index.browser.mjs
CHANGED
|
@@ -113,7 +113,7 @@ var FatalError = class extends Error {
|
|
|
113
113
|
var defaultTokens = [{
|
|
114
114
|
name: "Starknet",
|
|
115
115
|
symbol: "STRK",
|
|
116
|
-
logo: "https://assets.
|
|
116
|
+
logo: "https://assets.strkfarm.com/integrations/tokens/strk.svg",
|
|
117
117
|
address: ContractAddr.from("0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d"),
|
|
118
118
|
decimals: 18,
|
|
119
119
|
coingeckId: "starknet",
|
|
@@ -121,7 +121,7 @@ var defaultTokens = [{
|
|
|
121
121
|
}, {
|
|
122
122
|
name: "xSTRK",
|
|
123
123
|
symbol: "xSTRK",
|
|
124
|
-
logo: "https://
|
|
124
|
+
logo: "https://assets.strkfarm.com/integrations/tokens/xstrk.svg",
|
|
125
125
|
address: ContractAddr.from("0x028d709c875c0ceac3dce7065bec5328186dc89fe254527084d1689910954b0a"),
|
|
126
126
|
decimals: 18,
|
|
127
127
|
coingeckId: void 0,
|
|
@@ -129,7 +129,7 @@ var defaultTokens = [{
|
|
|
129
129
|
}, {
|
|
130
130
|
name: "ETH",
|
|
131
131
|
symbol: "ETH",
|
|
132
|
-
logo: "https://
|
|
132
|
+
logo: "https://assets.strkfarm.com/integrations/tokens/eth.svg",
|
|
133
133
|
address: ContractAddr.from("0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"),
|
|
134
134
|
decimals: 18,
|
|
135
135
|
coingeckId: void 0,
|
|
@@ -137,7 +137,7 @@ var defaultTokens = [{
|
|
|
137
137
|
}, {
|
|
138
138
|
name: "USDC",
|
|
139
139
|
symbol: "USDC",
|
|
140
|
-
logo: "https://
|
|
140
|
+
logo: "https://assets.strkfarm.com/integrations/tokens/usdc.svg",
|
|
141
141
|
address: ContractAddr.from("0x53c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8"),
|
|
142
142
|
decimals: 6,
|
|
143
143
|
coingeckId: void 0,
|
|
@@ -145,7 +145,7 @@ var defaultTokens = [{
|
|
|
145
145
|
}, {
|
|
146
146
|
name: "USDT",
|
|
147
147
|
symbol: "USDT",
|
|
148
|
-
logo: "https://assets.
|
|
148
|
+
logo: "https://assets.strkfarm.com/integrations/tokens/usdc.svg",
|
|
149
149
|
address: ContractAddr.from("0x68f5c6a61780768455de69077e07e89787839bf8166decfbf92b645209c0fb8"),
|
|
150
150
|
decimals: 6,
|
|
151
151
|
coingeckId: void 0,
|
|
@@ -153,7 +153,7 @@ var defaultTokens = [{
|
|
|
153
153
|
}, {
|
|
154
154
|
name: "WBTC",
|
|
155
155
|
symbol: "WBTC",
|
|
156
|
-
logo: "https://
|
|
156
|
+
logo: "https://assets.strkfarm.com/integrations/tokens/wbtc.svg",
|
|
157
157
|
address: ContractAddr.from("0x3fe2b97c1fd336e750087d68b9b867997fd64a2661ff3ca5a7c771641e8e7ac"),
|
|
158
158
|
decimals: 8,
|
|
159
159
|
coingeckId: void 0,
|
|
@@ -177,7 +177,7 @@ var Global = class _Global {
|
|
|
177
177
|
}
|
|
178
178
|
static async getTokens() {
|
|
179
179
|
if (tokens.length) return tokens;
|
|
180
|
-
const data = await axios.get("https://
|
|
180
|
+
const data = await axios.get("https://assets.strkfarm.com/integrations/tokens.json");
|
|
181
181
|
const tokensData = data.data.content;
|
|
182
182
|
tokensData.forEach((token) => {
|
|
183
183
|
if (!token.tags.includes("AVNU") || !token.tags.includes("Verified")) {
|
|
@@ -18630,11 +18630,10 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
|
|
|
18630
18630
|
* @returns Array of contract calls needed for rebalancing
|
|
18631
18631
|
* @throws Error if max retries reached without successful rebalance
|
|
18632
18632
|
*/
|
|
18633
|
-
async rebalanceIter(swapInfo, acc, estimateCall, retry = 0,
|
|
18634
|
-
const MAX_RETRIES =
|
|
18635
|
-
const MIN_ADJUSTMENT = 1e-3;
|
|
18633
|
+
async rebalanceIter(swapInfo, acc, estimateCall, isSellTokenToken0 = true, retry = 0, lowerLimit = 0n, upperLimit = 0n) {
|
|
18634
|
+
const MAX_RETRIES = 40;
|
|
18636
18635
|
logger.verbose(
|
|
18637
|
-
`Rebalancing ${this.metadata.name}: retry=${retry},
|
|
18636
|
+
`Rebalancing ${this.metadata.name}: retry=${retry}, lowerLimit=${lowerLimit}, upperLimit=${upperLimit}, isSellTokenToken0=${isSellTokenToken0}`
|
|
18638
18637
|
);
|
|
18639
18638
|
const fromAmount = uint2564.uint256ToBN(swapInfo.token_from_amount);
|
|
18640
18639
|
logger.verbose(
|
|
@@ -18649,38 +18648,69 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
|
|
|
18649
18648
|
logger.error(`Rebalance failed after ${MAX_RETRIES} retries`);
|
|
18650
18649
|
throw err;
|
|
18651
18650
|
}
|
|
18652
|
-
if (adjustmentFactor < MIN_ADJUSTMENT) {
|
|
18653
|
-
logger.error("Adjustment factor too small, likely oscillating");
|
|
18654
|
-
throw new Error("Failed to converge on valid swap amount");
|
|
18655
|
-
}
|
|
18656
18651
|
logger.error(`Rebalance attempt ${retry + 1} failed, adjusting swap amount...`);
|
|
18657
18652
|
const newSwapInfo = { ...swapInfo };
|
|
18658
18653
|
const currentAmount = Web3Number.fromWei(fromAmount.toString(), 18);
|
|
18654
|
+
logger.verbose(`Current amount: ${currentAmount.toString()}`);
|
|
18659
18655
|
if (err.message.includes("invalid token0 balance") || err.message.includes("invalid token0 amount")) {
|
|
18660
|
-
|
|
18661
|
-
|
|
18662
|
-
|
|
18663
|
-
|
|
18664
|
-
|
|
18665
|
-
|
|
18666
|
-
|
|
18667
|
-
|
|
18668
|
-
|
|
18669
|
-
|
|
18670
|
-
|
|
18671
|
-
|
|
18672
|
-
|
|
18656
|
+
if (!isSellTokenToken0) {
|
|
18657
|
+
logger.verbose("Reducing swap amount - excess token0");
|
|
18658
|
+
let nextAmount = (fromAmount + lowerLimit) / 2n;
|
|
18659
|
+
upperLimit = fromAmount;
|
|
18660
|
+
if (nextAmount <= lowerLimit) {
|
|
18661
|
+
logger.error("Convergence failed: nextAmount <= lowerLimit");
|
|
18662
|
+
throw err;
|
|
18663
|
+
}
|
|
18664
|
+
newSwapInfo.token_from_amount = uint2564.bnToUint256(nextAmount);
|
|
18665
|
+
} else {
|
|
18666
|
+
logger.verbose("Increasing swap amount - deficit token0");
|
|
18667
|
+
let nextAmount = (fromAmount + upperLimit) / 2n;
|
|
18668
|
+
if (upperLimit == 0n) {
|
|
18669
|
+
nextAmount = fromAmount * 2n;
|
|
18670
|
+
}
|
|
18671
|
+
lowerLimit = fromAmount;
|
|
18672
|
+
if (upperLimit != 0n && nextAmount >= upperLimit) {
|
|
18673
|
+
logger.error("Convergence failed: nextAmount >= upperLimit");
|
|
18674
|
+
throw err;
|
|
18675
|
+
}
|
|
18676
|
+
newSwapInfo.token_from_amount = uint2564.bnToUint256(nextAmount);
|
|
18677
|
+
}
|
|
18678
|
+
} else if (err.message.includes("invalid token1 amount") || err.message.includes("invalid token1 balance")) {
|
|
18679
|
+
if (isSellTokenToken0) {
|
|
18680
|
+
logger.verbose("Reducing swap amount - excess token1");
|
|
18681
|
+
let nextAmount = (fromAmount + lowerLimit) / 2n;
|
|
18682
|
+
upperLimit = fromAmount;
|
|
18683
|
+
if (nextAmount <= lowerLimit) {
|
|
18684
|
+
logger.error("Convergence failed: nextAmount <= lowerLimit");
|
|
18685
|
+
throw err;
|
|
18686
|
+
}
|
|
18687
|
+
newSwapInfo.token_from_amount = uint2564.bnToUint256(nextAmount);
|
|
18688
|
+
} else {
|
|
18689
|
+
logger.verbose("Increasing swap amount - deficit token1");
|
|
18690
|
+
let nextAmount = (fromAmount + upperLimit) / 2n;
|
|
18691
|
+
if (upperLimit == 0n) {
|
|
18692
|
+
nextAmount = fromAmount * 2n;
|
|
18693
|
+
}
|
|
18694
|
+
lowerLimit = fromAmount;
|
|
18695
|
+
if (upperLimit != 0n && nextAmount >= upperLimit) {
|
|
18696
|
+
logger.error("Convergence failed: nextAmount >= upperLimit");
|
|
18697
|
+
throw err;
|
|
18698
|
+
}
|
|
18699
|
+
newSwapInfo.token_from_amount = uint2564.bnToUint256(nextAmount);
|
|
18700
|
+
}
|
|
18673
18701
|
} else {
|
|
18674
18702
|
logger.error("Unexpected error:", err);
|
|
18703
|
+
throw err;
|
|
18675
18704
|
}
|
|
18676
18705
|
newSwapInfo.token_to_min_amount = uint2564.bnToUint256("0");
|
|
18677
18706
|
return this.rebalanceIter(
|
|
18678
18707
|
newSwapInfo,
|
|
18679
18708
|
acc,
|
|
18680
18709
|
estimateCall,
|
|
18710
|
+
isSellTokenToken0,
|
|
18681
18711
|
retry + 1,
|
|
18682
|
-
|
|
18683
|
-
|
|
18712
|
+
lowerLimit,
|
|
18713
|
+
upperLimit
|
|
18684
18714
|
);
|
|
18685
18715
|
}
|
|
18686
18716
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -717,7 +717,7 @@ declare class EkuboCLVault extends BaseStrategy<DualTokenInfo, DualActionAmount>
|
|
|
717
717
|
* @returns Array of contract calls needed for rebalancing
|
|
718
718
|
* @throws Error if max retries reached without successful rebalance
|
|
719
719
|
*/
|
|
720
|
-
rebalanceIter(swapInfo: SwapInfo, acc: Account, estimateCall: (swapInfo: SwapInfo) => Promise<Call[]>, retry?: number,
|
|
720
|
+
rebalanceIter(swapInfo: SwapInfo, acc: Account, estimateCall: (swapInfo: SwapInfo) => Promise<Call[]>, isSellTokenToken0?: boolean, retry?: number, lowerLimit?: bigint, upperLimit?: bigint): Promise<Call[]>;
|
|
721
721
|
static tickToi129(tick: number): {
|
|
722
722
|
mag: number;
|
|
723
723
|
sign: number;
|
package/dist/index.js
CHANGED
|
@@ -194,7 +194,7 @@ var FatalError = class extends Error {
|
|
|
194
194
|
var defaultTokens = [{
|
|
195
195
|
name: "Starknet",
|
|
196
196
|
symbol: "STRK",
|
|
197
|
-
logo: "https://assets.
|
|
197
|
+
logo: "https://assets.strkfarm.com/integrations/tokens/strk.svg",
|
|
198
198
|
address: ContractAddr.from("0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d"),
|
|
199
199
|
decimals: 18,
|
|
200
200
|
coingeckId: "starknet",
|
|
@@ -202,7 +202,7 @@ var defaultTokens = [{
|
|
|
202
202
|
}, {
|
|
203
203
|
name: "xSTRK",
|
|
204
204
|
symbol: "xSTRK",
|
|
205
|
-
logo: "https://
|
|
205
|
+
logo: "https://assets.strkfarm.com/integrations/tokens/xstrk.svg",
|
|
206
206
|
address: ContractAddr.from("0x028d709c875c0ceac3dce7065bec5328186dc89fe254527084d1689910954b0a"),
|
|
207
207
|
decimals: 18,
|
|
208
208
|
coingeckId: void 0,
|
|
@@ -210,7 +210,7 @@ var defaultTokens = [{
|
|
|
210
210
|
}, {
|
|
211
211
|
name: "ETH",
|
|
212
212
|
symbol: "ETH",
|
|
213
|
-
logo: "https://
|
|
213
|
+
logo: "https://assets.strkfarm.com/integrations/tokens/eth.svg",
|
|
214
214
|
address: ContractAddr.from("0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"),
|
|
215
215
|
decimals: 18,
|
|
216
216
|
coingeckId: void 0,
|
|
@@ -218,7 +218,7 @@ var defaultTokens = [{
|
|
|
218
218
|
}, {
|
|
219
219
|
name: "USDC",
|
|
220
220
|
symbol: "USDC",
|
|
221
|
-
logo: "https://
|
|
221
|
+
logo: "https://assets.strkfarm.com/integrations/tokens/usdc.svg",
|
|
222
222
|
address: ContractAddr.from("0x53c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8"),
|
|
223
223
|
decimals: 6,
|
|
224
224
|
coingeckId: void 0,
|
|
@@ -226,7 +226,7 @@ var defaultTokens = [{
|
|
|
226
226
|
}, {
|
|
227
227
|
name: "USDT",
|
|
228
228
|
symbol: "USDT",
|
|
229
|
-
logo: "https://assets.
|
|
229
|
+
logo: "https://assets.strkfarm.com/integrations/tokens/usdc.svg",
|
|
230
230
|
address: ContractAddr.from("0x68f5c6a61780768455de69077e07e89787839bf8166decfbf92b645209c0fb8"),
|
|
231
231
|
decimals: 6,
|
|
232
232
|
coingeckId: void 0,
|
|
@@ -234,7 +234,7 @@ var defaultTokens = [{
|
|
|
234
234
|
}, {
|
|
235
235
|
name: "WBTC",
|
|
236
236
|
symbol: "WBTC",
|
|
237
|
-
logo: "https://
|
|
237
|
+
logo: "https://assets.strkfarm.com/integrations/tokens/wbtc.svg",
|
|
238
238
|
address: ContractAddr.from("0x3fe2b97c1fd336e750087d68b9b867997fd64a2661ff3ca5a7c771641e8e7ac"),
|
|
239
239
|
decimals: 8,
|
|
240
240
|
coingeckId: void 0,
|
|
@@ -258,7 +258,7 @@ var Global = class _Global {
|
|
|
258
258
|
}
|
|
259
259
|
static async getTokens() {
|
|
260
260
|
if (tokens.length) return tokens;
|
|
261
|
-
const data = await import_axios.default.get("https://
|
|
261
|
+
const data = await import_axios.default.get("https://assets.strkfarm.com/integrations/tokens.json");
|
|
262
262
|
const tokensData = data.data.content;
|
|
263
263
|
tokensData.forEach((token) => {
|
|
264
264
|
if (!token.tags.includes("AVNU") || !token.tags.includes("Verified")) {
|
|
@@ -18719,11 +18719,10 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
|
|
|
18719
18719
|
* @returns Array of contract calls needed for rebalancing
|
|
18720
18720
|
* @throws Error if max retries reached without successful rebalance
|
|
18721
18721
|
*/
|
|
18722
|
-
async rebalanceIter(swapInfo, acc, estimateCall, retry = 0,
|
|
18723
|
-
const MAX_RETRIES =
|
|
18724
|
-
const MIN_ADJUSTMENT = 1e-3;
|
|
18722
|
+
async rebalanceIter(swapInfo, acc, estimateCall, isSellTokenToken0 = true, retry = 0, lowerLimit = 0n, upperLimit = 0n) {
|
|
18723
|
+
const MAX_RETRIES = 40;
|
|
18725
18724
|
logger.verbose(
|
|
18726
|
-
`Rebalancing ${this.metadata.name}: retry=${retry},
|
|
18725
|
+
`Rebalancing ${this.metadata.name}: retry=${retry}, lowerLimit=${lowerLimit}, upperLimit=${upperLimit}, isSellTokenToken0=${isSellTokenToken0}`
|
|
18727
18726
|
);
|
|
18728
18727
|
const fromAmount = import_starknet9.uint256.uint256ToBN(swapInfo.token_from_amount);
|
|
18729
18728
|
logger.verbose(
|
|
@@ -18738,38 +18737,69 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
|
|
|
18738
18737
|
logger.error(`Rebalance failed after ${MAX_RETRIES} retries`);
|
|
18739
18738
|
throw err;
|
|
18740
18739
|
}
|
|
18741
|
-
if (adjustmentFactor < MIN_ADJUSTMENT) {
|
|
18742
|
-
logger.error("Adjustment factor too small, likely oscillating");
|
|
18743
|
-
throw new Error("Failed to converge on valid swap amount");
|
|
18744
|
-
}
|
|
18745
18740
|
logger.error(`Rebalance attempt ${retry + 1} failed, adjusting swap amount...`);
|
|
18746
18741
|
const newSwapInfo = { ...swapInfo };
|
|
18747
18742
|
const currentAmount = Web3Number.fromWei(fromAmount.toString(), 18);
|
|
18743
|
+
logger.verbose(`Current amount: ${currentAmount.toString()}`);
|
|
18748
18744
|
if (err.message.includes("invalid token0 balance") || err.message.includes("invalid token0 amount")) {
|
|
18749
|
-
|
|
18750
|
-
|
|
18751
|
-
|
|
18752
|
-
|
|
18753
|
-
|
|
18754
|
-
|
|
18755
|
-
|
|
18756
|
-
|
|
18757
|
-
|
|
18758
|
-
|
|
18759
|
-
|
|
18760
|
-
|
|
18761
|
-
|
|
18745
|
+
if (!isSellTokenToken0) {
|
|
18746
|
+
logger.verbose("Reducing swap amount - excess token0");
|
|
18747
|
+
let nextAmount = (fromAmount + lowerLimit) / 2n;
|
|
18748
|
+
upperLimit = fromAmount;
|
|
18749
|
+
if (nextAmount <= lowerLimit) {
|
|
18750
|
+
logger.error("Convergence failed: nextAmount <= lowerLimit");
|
|
18751
|
+
throw err;
|
|
18752
|
+
}
|
|
18753
|
+
newSwapInfo.token_from_amount = import_starknet9.uint256.bnToUint256(nextAmount);
|
|
18754
|
+
} else {
|
|
18755
|
+
logger.verbose("Increasing swap amount - deficit token0");
|
|
18756
|
+
let nextAmount = (fromAmount + upperLimit) / 2n;
|
|
18757
|
+
if (upperLimit == 0n) {
|
|
18758
|
+
nextAmount = fromAmount * 2n;
|
|
18759
|
+
}
|
|
18760
|
+
lowerLimit = fromAmount;
|
|
18761
|
+
if (upperLimit != 0n && nextAmount >= upperLimit) {
|
|
18762
|
+
logger.error("Convergence failed: nextAmount >= upperLimit");
|
|
18763
|
+
throw err;
|
|
18764
|
+
}
|
|
18765
|
+
newSwapInfo.token_from_amount = import_starknet9.uint256.bnToUint256(nextAmount);
|
|
18766
|
+
}
|
|
18767
|
+
} else if (err.message.includes("invalid token1 amount") || err.message.includes("invalid token1 balance")) {
|
|
18768
|
+
if (isSellTokenToken0) {
|
|
18769
|
+
logger.verbose("Reducing swap amount - excess token1");
|
|
18770
|
+
let nextAmount = (fromAmount + lowerLimit) / 2n;
|
|
18771
|
+
upperLimit = fromAmount;
|
|
18772
|
+
if (nextAmount <= lowerLimit) {
|
|
18773
|
+
logger.error("Convergence failed: nextAmount <= lowerLimit");
|
|
18774
|
+
throw err;
|
|
18775
|
+
}
|
|
18776
|
+
newSwapInfo.token_from_amount = import_starknet9.uint256.bnToUint256(nextAmount);
|
|
18777
|
+
} else {
|
|
18778
|
+
logger.verbose("Increasing swap amount - deficit token1");
|
|
18779
|
+
let nextAmount = (fromAmount + upperLimit) / 2n;
|
|
18780
|
+
if (upperLimit == 0n) {
|
|
18781
|
+
nextAmount = fromAmount * 2n;
|
|
18782
|
+
}
|
|
18783
|
+
lowerLimit = fromAmount;
|
|
18784
|
+
if (upperLimit != 0n && nextAmount >= upperLimit) {
|
|
18785
|
+
logger.error("Convergence failed: nextAmount >= upperLimit");
|
|
18786
|
+
throw err;
|
|
18787
|
+
}
|
|
18788
|
+
newSwapInfo.token_from_amount = import_starknet9.uint256.bnToUint256(nextAmount);
|
|
18789
|
+
}
|
|
18762
18790
|
} else {
|
|
18763
18791
|
logger.error("Unexpected error:", err);
|
|
18792
|
+
throw err;
|
|
18764
18793
|
}
|
|
18765
18794
|
newSwapInfo.token_to_min_amount = import_starknet9.uint256.bnToUint256("0");
|
|
18766
18795
|
return this.rebalanceIter(
|
|
18767
18796
|
newSwapInfo,
|
|
18768
18797
|
acc,
|
|
18769
18798
|
estimateCall,
|
|
18799
|
+
isSellTokenToken0,
|
|
18770
18800
|
retry + 1,
|
|
18771
|
-
|
|
18772
|
-
|
|
18801
|
+
lowerLimit,
|
|
18802
|
+
upperLimit
|
|
18773
18803
|
);
|
|
18774
18804
|
}
|
|
18775
18805
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -125,7 +125,7 @@ var FatalError = class extends Error {
|
|
|
125
125
|
var defaultTokens = [{
|
|
126
126
|
name: "Starknet",
|
|
127
127
|
symbol: "STRK",
|
|
128
|
-
logo: "https://assets.
|
|
128
|
+
logo: "https://assets.strkfarm.com/integrations/tokens/strk.svg",
|
|
129
129
|
address: ContractAddr.from("0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d"),
|
|
130
130
|
decimals: 18,
|
|
131
131
|
coingeckId: "starknet",
|
|
@@ -133,7 +133,7 @@ var defaultTokens = [{
|
|
|
133
133
|
}, {
|
|
134
134
|
name: "xSTRK",
|
|
135
135
|
symbol: "xSTRK",
|
|
136
|
-
logo: "https://
|
|
136
|
+
logo: "https://assets.strkfarm.com/integrations/tokens/xstrk.svg",
|
|
137
137
|
address: ContractAddr.from("0x028d709c875c0ceac3dce7065bec5328186dc89fe254527084d1689910954b0a"),
|
|
138
138
|
decimals: 18,
|
|
139
139
|
coingeckId: void 0,
|
|
@@ -141,7 +141,7 @@ var defaultTokens = [{
|
|
|
141
141
|
}, {
|
|
142
142
|
name: "ETH",
|
|
143
143
|
symbol: "ETH",
|
|
144
|
-
logo: "https://
|
|
144
|
+
logo: "https://assets.strkfarm.com/integrations/tokens/eth.svg",
|
|
145
145
|
address: ContractAddr.from("0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"),
|
|
146
146
|
decimals: 18,
|
|
147
147
|
coingeckId: void 0,
|
|
@@ -149,7 +149,7 @@ var defaultTokens = [{
|
|
|
149
149
|
}, {
|
|
150
150
|
name: "USDC",
|
|
151
151
|
symbol: "USDC",
|
|
152
|
-
logo: "https://
|
|
152
|
+
logo: "https://assets.strkfarm.com/integrations/tokens/usdc.svg",
|
|
153
153
|
address: ContractAddr.from("0x53c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8"),
|
|
154
154
|
decimals: 6,
|
|
155
155
|
coingeckId: void 0,
|
|
@@ -157,7 +157,7 @@ var defaultTokens = [{
|
|
|
157
157
|
}, {
|
|
158
158
|
name: "USDT",
|
|
159
159
|
symbol: "USDT",
|
|
160
|
-
logo: "https://assets.
|
|
160
|
+
logo: "https://assets.strkfarm.com/integrations/tokens/usdc.svg",
|
|
161
161
|
address: ContractAddr.from("0x68f5c6a61780768455de69077e07e89787839bf8166decfbf92b645209c0fb8"),
|
|
162
162
|
decimals: 6,
|
|
163
163
|
coingeckId: void 0,
|
|
@@ -165,7 +165,7 @@ var defaultTokens = [{
|
|
|
165
165
|
}, {
|
|
166
166
|
name: "WBTC",
|
|
167
167
|
symbol: "WBTC",
|
|
168
|
-
logo: "https://
|
|
168
|
+
logo: "https://assets.strkfarm.com/integrations/tokens/wbtc.svg",
|
|
169
169
|
address: ContractAddr.from("0x3fe2b97c1fd336e750087d68b9b867997fd64a2661ff3ca5a7c771641e8e7ac"),
|
|
170
170
|
decimals: 8,
|
|
171
171
|
coingeckId: void 0,
|
|
@@ -189,7 +189,7 @@ var Global = class _Global {
|
|
|
189
189
|
}
|
|
190
190
|
static async getTokens() {
|
|
191
191
|
if (tokens.length) return tokens;
|
|
192
|
-
const data = await axios.get("https://
|
|
192
|
+
const data = await axios.get("https://assets.strkfarm.com/integrations/tokens.json");
|
|
193
193
|
const tokensData = data.data.content;
|
|
194
194
|
tokensData.forEach((token) => {
|
|
195
195
|
if (!token.tags.includes("AVNU") || !token.tags.includes("Verified")) {
|
|
@@ -18650,11 +18650,10 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
|
|
|
18650
18650
|
* @returns Array of contract calls needed for rebalancing
|
|
18651
18651
|
* @throws Error if max retries reached without successful rebalance
|
|
18652
18652
|
*/
|
|
18653
|
-
async rebalanceIter(swapInfo, acc, estimateCall, retry = 0,
|
|
18654
|
-
const MAX_RETRIES =
|
|
18655
|
-
const MIN_ADJUSTMENT = 1e-3;
|
|
18653
|
+
async rebalanceIter(swapInfo, acc, estimateCall, isSellTokenToken0 = true, retry = 0, lowerLimit = 0n, upperLimit = 0n) {
|
|
18654
|
+
const MAX_RETRIES = 40;
|
|
18656
18655
|
logger.verbose(
|
|
18657
|
-
`Rebalancing ${this.metadata.name}: retry=${retry},
|
|
18656
|
+
`Rebalancing ${this.metadata.name}: retry=${retry}, lowerLimit=${lowerLimit}, upperLimit=${upperLimit}, isSellTokenToken0=${isSellTokenToken0}`
|
|
18658
18657
|
);
|
|
18659
18658
|
const fromAmount = uint2564.uint256ToBN(swapInfo.token_from_amount);
|
|
18660
18659
|
logger.verbose(
|
|
@@ -18669,38 +18668,69 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
|
|
|
18669
18668
|
logger.error(`Rebalance failed after ${MAX_RETRIES} retries`);
|
|
18670
18669
|
throw err;
|
|
18671
18670
|
}
|
|
18672
|
-
if (adjustmentFactor < MIN_ADJUSTMENT) {
|
|
18673
|
-
logger.error("Adjustment factor too small, likely oscillating");
|
|
18674
|
-
throw new Error("Failed to converge on valid swap amount");
|
|
18675
|
-
}
|
|
18676
18671
|
logger.error(`Rebalance attempt ${retry + 1} failed, adjusting swap amount...`);
|
|
18677
18672
|
const newSwapInfo = { ...swapInfo };
|
|
18678
18673
|
const currentAmount = Web3Number.fromWei(fromAmount.toString(), 18);
|
|
18674
|
+
logger.verbose(`Current amount: ${currentAmount.toString()}`);
|
|
18679
18675
|
if (err.message.includes("invalid token0 balance") || err.message.includes("invalid token0 amount")) {
|
|
18680
|
-
|
|
18681
|
-
|
|
18682
|
-
|
|
18683
|
-
|
|
18684
|
-
|
|
18685
|
-
|
|
18686
|
-
|
|
18687
|
-
|
|
18688
|
-
|
|
18689
|
-
|
|
18690
|
-
|
|
18691
|
-
|
|
18692
|
-
|
|
18676
|
+
if (!isSellTokenToken0) {
|
|
18677
|
+
logger.verbose("Reducing swap amount - excess token0");
|
|
18678
|
+
let nextAmount = (fromAmount + lowerLimit) / 2n;
|
|
18679
|
+
upperLimit = fromAmount;
|
|
18680
|
+
if (nextAmount <= lowerLimit) {
|
|
18681
|
+
logger.error("Convergence failed: nextAmount <= lowerLimit");
|
|
18682
|
+
throw err;
|
|
18683
|
+
}
|
|
18684
|
+
newSwapInfo.token_from_amount = uint2564.bnToUint256(nextAmount);
|
|
18685
|
+
} else {
|
|
18686
|
+
logger.verbose("Increasing swap amount - deficit token0");
|
|
18687
|
+
let nextAmount = (fromAmount + upperLimit) / 2n;
|
|
18688
|
+
if (upperLimit == 0n) {
|
|
18689
|
+
nextAmount = fromAmount * 2n;
|
|
18690
|
+
}
|
|
18691
|
+
lowerLimit = fromAmount;
|
|
18692
|
+
if (upperLimit != 0n && nextAmount >= upperLimit) {
|
|
18693
|
+
logger.error("Convergence failed: nextAmount >= upperLimit");
|
|
18694
|
+
throw err;
|
|
18695
|
+
}
|
|
18696
|
+
newSwapInfo.token_from_amount = uint2564.bnToUint256(nextAmount);
|
|
18697
|
+
}
|
|
18698
|
+
} else if (err.message.includes("invalid token1 amount") || err.message.includes("invalid token1 balance")) {
|
|
18699
|
+
if (isSellTokenToken0) {
|
|
18700
|
+
logger.verbose("Reducing swap amount - excess token1");
|
|
18701
|
+
let nextAmount = (fromAmount + lowerLimit) / 2n;
|
|
18702
|
+
upperLimit = fromAmount;
|
|
18703
|
+
if (nextAmount <= lowerLimit) {
|
|
18704
|
+
logger.error("Convergence failed: nextAmount <= lowerLimit");
|
|
18705
|
+
throw err;
|
|
18706
|
+
}
|
|
18707
|
+
newSwapInfo.token_from_amount = uint2564.bnToUint256(nextAmount);
|
|
18708
|
+
} else {
|
|
18709
|
+
logger.verbose("Increasing swap amount - deficit token1");
|
|
18710
|
+
let nextAmount = (fromAmount + upperLimit) / 2n;
|
|
18711
|
+
if (upperLimit == 0n) {
|
|
18712
|
+
nextAmount = fromAmount * 2n;
|
|
18713
|
+
}
|
|
18714
|
+
lowerLimit = fromAmount;
|
|
18715
|
+
if (upperLimit != 0n && nextAmount >= upperLimit) {
|
|
18716
|
+
logger.error("Convergence failed: nextAmount >= upperLimit");
|
|
18717
|
+
throw err;
|
|
18718
|
+
}
|
|
18719
|
+
newSwapInfo.token_from_amount = uint2564.bnToUint256(nextAmount);
|
|
18720
|
+
}
|
|
18693
18721
|
} else {
|
|
18694
18722
|
logger.error("Unexpected error:", err);
|
|
18723
|
+
throw err;
|
|
18695
18724
|
}
|
|
18696
18725
|
newSwapInfo.token_to_min_amount = uint2564.bnToUint256("0");
|
|
18697
18726
|
return this.rebalanceIter(
|
|
18698
18727
|
newSwapInfo,
|
|
18699
18728
|
acc,
|
|
18700
18729
|
estimateCall,
|
|
18730
|
+
isSellTokenToken0,
|
|
18701
18731
|
retry + 1,
|
|
18702
|
-
|
|
18703
|
-
|
|
18732
|
+
lowerLimit,
|
|
18733
|
+
upperLimit
|
|
18704
18734
|
);
|
|
18705
18735
|
}
|
|
18706
18736
|
}
|
package/package.json
CHANGED
package/src/global.ts
CHANGED
|
@@ -49,7 +49,7 @@ export class FatalError extends Error {
|
|
|
49
49
|
const defaultTokens: TokenInfo[] = [{
|
|
50
50
|
name: 'Starknet',
|
|
51
51
|
symbol: 'STRK',
|
|
52
|
-
logo: 'https://assets.
|
|
52
|
+
logo: 'https://assets.strkfarm.com/integrations/tokens/strk.svg',
|
|
53
53
|
address: ContractAddr.from('0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d'),
|
|
54
54
|
decimals: 18,
|
|
55
55
|
coingeckId: 'starknet',
|
|
@@ -57,7 +57,7 @@ const defaultTokens: TokenInfo[] = [{
|
|
|
57
57
|
}, {
|
|
58
58
|
name: 'xSTRK',
|
|
59
59
|
symbol: 'xSTRK',
|
|
60
|
-
logo: 'https://
|
|
60
|
+
logo: 'https://assets.strkfarm.com/integrations/tokens/xstrk.svg',
|
|
61
61
|
address: ContractAddr.from('0x028d709c875c0ceac3dce7065bec5328186dc89fe254527084d1689910954b0a'),
|
|
62
62
|
decimals: 18,
|
|
63
63
|
coingeckId: undefined,
|
|
@@ -65,7 +65,7 @@ const defaultTokens: TokenInfo[] = [{
|
|
|
65
65
|
}, {
|
|
66
66
|
name: 'ETH',
|
|
67
67
|
symbol: 'ETH',
|
|
68
|
-
logo: 'https://
|
|
68
|
+
logo: 'https://assets.strkfarm.com/integrations/tokens/eth.svg',
|
|
69
69
|
address: ContractAddr.from('0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7'),
|
|
70
70
|
decimals: 18,
|
|
71
71
|
coingeckId: undefined,
|
|
@@ -73,7 +73,7 @@ const defaultTokens: TokenInfo[] = [{
|
|
|
73
73
|
}, {
|
|
74
74
|
name: 'USDC',
|
|
75
75
|
symbol: 'USDC',
|
|
76
|
-
logo: 'https://
|
|
76
|
+
logo: 'https://assets.strkfarm.com/integrations/tokens/usdc.svg',
|
|
77
77
|
address: ContractAddr.from('0x53c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8'),
|
|
78
78
|
decimals: 6,
|
|
79
79
|
coingeckId: undefined,
|
|
@@ -81,7 +81,7 @@ const defaultTokens: TokenInfo[] = [{
|
|
|
81
81
|
}, {
|
|
82
82
|
name: 'USDT',
|
|
83
83
|
symbol: 'USDT',
|
|
84
|
-
logo: 'https://assets.
|
|
84
|
+
logo: 'https://assets.strkfarm.com/integrations/tokens/usdc.svg',
|
|
85
85
|
address: ContractAddr.from('0x68f5c6a61780768455de69077e07e89787839bf8166decfbf92b645209c0fb8'),
|
|
86
86
|
decimals: 6,
|
|
87
87
|
coingeckId: undefined,
|
|
@@ -89,7 +89,7 @@ const defaultTokens: TokenInfo[] = [{
|
|
|
89
89
|
}, {
|
|
90
90
|
name: 'WBTC',
|
|
91
91
|
symbol: 'WBTC',
|
|
92
|
-
logo: 'https://
|
|
92
|
+
logo: 'https://assets.strkfarm.com/integrations/tokens/wbtc.svg',
|
|
93
93
|
address: ContractAddr.from('0x3fe2b97c1fd336e750087d68b9b867997fd64a2661ff3ca5a7c771641e8e7ac'),
|
|
94
94
|
decimals: 8,
|
|
95
95
|
coingeckId: undefined,
|
|
@@ -122,7 +122,7 @@ export class Global {
|
|
|
122
122
|
if (tokens.length) return tokens;
|
|
123
123
|
|
|
124
124
|
// fetch from avnu API
|
|
125
|
-
const data = await axios.get('https://
|
|
125
|
+
const data = await axios.get('https://assets.strkfarm.com/integrations/tokens.json');
|
|
126
126
|
const tokensData = data.data.content;
|
|
127
127
|
|
|
128
128
|
// Array of the following is returned
|