@strkfarm/sdk 1.0.45 → 1.0.47

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.js CHANGED
@@ -15385,7 +15385,9 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
15385
15385
  console.log(
15386
15386
  `EkuboCLVault: getCurrentPrice: blockIdentifier: ${blockIdentifier}, sqrtRatio: ${sqrtRatio}, ${priceInfo.sqrt_ratio.toString()}`
15387
15387
  );
15388
- const price = sqrtRatio * sqrtRatio;
15388
+ const token0Info = await Global.getTokenInfoFromAddr(poolKey.token0);
15389
+ const token1Info = await Global.getTokenInfoFromAddr(poolKey.token1);
15390
+ const price = sqrtRatio * sqrtRatio * 10 ** token0Info.decimals / 10 ** token1Info.decimals;
15389
15391
  const tick = _EkuboCLVault.priceToTick(
15390
15392
  price,
15391
15393
  true,
@@ -15410,7 +15412,7 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
15410
15412
  };
15411
15413
  }
15412
15414
  static div2Power128(num5) {
15413
- return Number(BigInt(num5.toString()) * 1000000n / BigInt(2 ** 128)) / 1e6;
15415
+ return Number(BigInt(num5.toString()) * BigInt(1e18) / BigInt(2 ** 128)) / 1e18;
15414
15416
  }
15415
15417
  static priceToTick(price, isRoundDown, tickSpacing) {
15416
15418
  const value = isRoundDown ? Math.floor(Math.log(price) / Math.log(1.000001)) : Math.ceil(Math.log(price) / Math.log(1.000001));
@@ -15431,18 +15433,15 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
15431
15433
  tick_spacing: result.pool_key.tick_spacing.toString(),
15432
15434
  extension: result.pool_key.extension.toString()
15433
15435
  };
15434
- const token0Info = await Global.getTokenInfoFromAddr(poolKey.token0);
15435
- const token1Info = await Global.getTokenInfoFromAddr(poolKey.token1);
15436
- assert(
15437
- token0Info.decimals == token1Info.decimals,
15438
- "Tested only for equal decimals"
15439
- );
15440
15436
  this.poolKey = poolKey;
15441
15437
  return poolKey;
15442
15438
  }
15443
15439
  async getNewBounds() {
15444
15440
  const poolKey = await this.getPoolKey();
15445
15441
  const currentPrice = await this._getCurrentPrice(poolKey);
15442
+ if (typeof this.metadata.additionalInfo.newBounds === "string") {
15443
+ throw new Error(`New bounds are managed known, to be set manually/externally`);
15444
+ }
15446
15445
  const newLower = currentPrice.tick + Number(this.metadata.additionalInfo.newBounds.lower) * Number(poolKey.tick_spacing);
15447
15446
  const newUpper = currentPrice.tick + Number(this.metadata.additionalInfo.newBounds.upper) * Number(poolKey.tick_spacing);
15448
15447
  return {
@@ -15457,8 +15456,8 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
15457
15456
  * @param amount1: amount of token1
15458
15457
  * @returns {amount0, amount1}
15459
15458
  */
15460
- async _getExpectedAmountsForLiquidity(amount0, amount1, bounds, justUseInputAmount = true) {
15461
- assert(amount0.greaterThan(0) || amount1.greaterThan(0), "Amount is 0");
15459
+ async _getExpectedAmountsForLiquidity(inputAmount0, inputAmount1, bounds, justUseInputAmount = true) {
15460
+ assert(inputAmount0.greaterThan(0) || inputAmount1.greaterThan(0), "Amount is 0");
15462
15461
  const sampleLiq = 1e20;
15463
15462
  const { amount0: sampleAmount0, amount1: sampleAmount1 } = await this.getLiquidityToAmounts(
15464
15463
  Web3Number.fromWei(sampleLiq.toString(), 18),
@@ -15472,39 +15471,37 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
15472
15471
  logger.verbose(
15473
15472
  `${_EkuboCLVault.name}: _getExpectedAmountsForLiquidity => price: ${price}`
15474
15473
  );
15475
- if (amount1.eq(0) && amount0.greaterThan(0)) {
15474
+ if (inputAmount1.eq(0) && inputAmount0.greaterThan(0)) {
15476
15475
  if (sampleAmount1.eq(0)) {
15477
15476
  return {
15478
- amount0,
15479
- amount1: Web3Number.fromWei("0", amount1.decimals),
15477
+ amount0: inputAmount0,
15478
+ amount1: Web3Number.fromWei("0", inputAmount1.decimals),
15480
15479
  ratio: Infinity
15481
15480
  };
15482
15481
  } else if (sampleAmount0.eq(0)) {
15483
15482
  return {
15484
- amount0: Web3Number.fromWei("0", amount0.decimals),
15485
- amount1: amount0.multipliedBy(price),
15483
+ amount0: Web3Number.fromWei("0", inputAmount0.decimals),
15484
+ // to ensure decimal consistency, we start with 0
15485
+ amount1: Web3Number.fromWei("0", inputAmount1.decimals).plus(inputAmount0.toString()).multipliedBy(price),
15486
15486
  ratio: 0
15487
15487
  };
15488
15488
  }
15489
- } else if (amount0.eq(0) && amount1.greaterThan(0)) {
15489
+ } else if (inputAmount0.eq(0) && inputAmount1.greaterThan(0)) {
15490
15490
  if (sampleAmount0.eq(0)) {
15491
15491
  return {
15492
- amount0: Web3Number.fromWei("0", amount0.decimals),
15493
- amount1,
15492
+ amount0: Web3Number.fromWei("0", inputAmount0.decimals),
15493
+ amount1: inputAmount1,
15494
15494
  ratio: 0
15495
15495
  };
15496
15496
  } else if (sampleAmount1.eq(0)) {
15497
15497
  return {
15498
- amount0: amount1.dividedBy(price),
15499
- amount1: Web3Number.fromWei("0", amount1.decimals),
15498
+ // to ensure decimal consistency, we start with 0
15499
+ amount0: Web3Number.fromWei("0", inputAmount0.decimals).plus(inputAmount1.toString()).dividedBy(price),
15500
+ amount1: Web3Number.fromWei("0", inputAmount1.decimals),
15500
15501
  ratio: Infinity
15501
15502
  };
15502
15503
  }
15503
15504
  }
15504
- assert(
15505
- sampleAmount0.decimals == sampleAmount1.decimals,
15506
- "Sample amounts have different decimals"
15507
- );
15508
15505
  const ratioWeb3Number = sampleAmount0.multipliedBy(1e18).dividedBy(sampleAmount1.toString()).dividedBy(1e18);
15509
15506
  const ratio = Number(ratioWeb3Number.toFixed(18));
15510
15507
  logger.verbose(
@@ -15512,23 +15509,23 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
15512
15509
  );
15513
15510
  if (justUseInputAmount)
15514
15511
  return this._solveExpectedAmountsEq(
15515
- amount0,
15516
- amount1,
15512
+ inputAmount0,
15513
+ inputAmount1,
15517
15514
  ratioWeb3Number,
15518
15515
  price
15519
15516
  );
15520
- if (amount1.eq(0) && amount0.greaterThan(0)) {
15521
- const _amount1 = amount0.dividedBy(ratioWeb3Number);
15517
+ if (inputAmount1.eq(0) && inputAmount0.greaterThan(0)) {
15518
+ const _amount1 = new Web3Number(inputAmount0.toString(), inputAmount1.decimals).dividedBy(ratioWeb3Number);
15522
15519
  return {
15523
- amount0,
15520
+ amount0: inputAmount0,
15524
15521
  amount1: _amount1,
15525
15522
  ratio
15526
15523
  };
15527
- } else if (amount0.eq(0) && amount1.greaterThan(0)) {
15528
- const _amount0 = amount1.multipliedBy(ratio);
15524
+ } else if (inputAmount0.eq(0) && inputAmount1.greaterThan(0)) {
15525
+ const _amount0 = new Web3Number(inputAmount1.toString(), inputAmount0.decimals).multipliedBy(ratio);
15529
15526
  return {
15530
15527
  amount0: _amount0,
15531
- amount1,
15528
+ amount1: inputAmount1,
15532
15529
  ratio
15533
15530
  };
15534
15531
  } else {
@@ -15591,7 +15588,7 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
15591
15588
  }
15592
15589
  };
15593
15590
  }
15594
- async getSwapInfoToHandleUnused(considerRebalance = true) {
15591
+ async getSwapInfoToHandleUnused(considerRebalance = true, newBounds = null) {
15595
15592
  const poolKey = await this.getPoolKey();
15596
15593
  const unusedBalances = await this.unusedBalances(poolKey);
15597
15594
  const { amount: token0Bal1, usdValue: token0PriceUsd } = unusedBalances.token0;
@@ -15614,7 +15611,9 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
15614
15611
  `${_EkuboCLVault.name}: getSwapInfoToHandleUnused => token0Bal: ${token0Bal.toString()}, token1Bal: ${token1Bal.toString()}`
15615
15612
  );
15616
15613
  let ekuboBounds;
15617
- if (considerRebalance) {
15614
+ if (newBounds) {
15615
+ ekuboBounds = newBounds;
15616
+ } else if (considerRebalance) {
15618
15617
  ekuboBounds = await this.getNewBounds();
15619
15618
  } else {
15620
15619
  ekuboBounds = await this.getCurrentBounds();
@@ -15855,6 +15854,10 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
15855
15854
  return BigInt(Math.floor(Math.sqrt(price) * 10 ** 9)) * BigInt(2 ** 128) / BigInt(1e9);
15856
15855
  }
15857
15856
  static i129ToNumber(i129) {
15857
+ if (i129.sign == 0 || i129.sign == 1) {
15858
+ return _EkuboCLVault.i129ToNumber({ mag: i129.mag, sign: i129.sign == 1 ? "true" : "false" });
15859
+ }
15860
+ assert(i129.sign.toString() == "false" || i129.sign.toString() == "true", "Invalid sign value");
15858
15861
  return i129.mag * (i129.sign.toString() == "false" ? 1n : -1n);
15859
15862
  }
15860
15863
  static tickToPrice(tick) {
@@ -16033,7 +16036,7 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
16033
16036
  subItems: [
16034
16037
  {
16035
16038
  key: "Range selection",
16036
- value: `${this.metadata.additionalInfo.newBounds.lower * Number(poolKey.tick_spacing)} to ${this.metadata.additionalInfo.newBounds.upper * Number(poolKey.tick_spacing)} ticks`
16039
+ value: typeof this.metadata.additionalInfo.newBounds == "string" ? this.metadata.additionalInfo.newBounds : `${this.metadata.additionalInfo.newBounds.lower * Number(poolKey.tick_spacing)} to ${this.metadata.additionalInfo.newBounds.upper * Number(poolKey.tick_spacing)} ticks`
16037
16040
  }
16038
16041
  ],
16039
16042
  linkedFlows: [linkedFlow],
@@ -16085,73 +16088,74 @@ var faqs2 = [
16085
16088
  ] })
16086
16089
  }
16087
16090
  ];
16088
- var EkuboCLVaultStrategies = [
16089
- {
16090
- name: "Ekubo xSTRK/STRK",
16091
- description: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
16092
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { children: _description2.replace("{{POOL_NAME}}", "xSTRK/STRK") }),
16093
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
16094
- "ul",
16095
- {
16096
- style: {
16097
- marginLeft: "20px",
16098
- listStyle: "circle",
16099
- fontSize: "12px"
16100
- },
16101
- children: [
16102
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("li", { style: { marginTop: "10px" }, children: "During withdrawal, you may receive either or both tokens depending on market conditions and prevailing prices." }),
16103
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("li", { style: { marginTop: "10px" }, children: "Sometimes you might see a negative APY \u2014 this is usually not a big deal. It happens when xSTRK's price drops on DEXes, but things typically bounce back within a few days or a week." })
16104
- ]
16105
- }
16106
- )
16107
- ] }),
16108
- address: ContractAddr.from(
16109
- "0x01f083b98674bc21effee29ef443a00c7b9a500fd92cf30341a3da12c73f2324"
16110
- ),
16111
- launchBlock: 1209881,
16112
- type: "Other",
16113
- // must be same order as poolKey token0 and token1
16114
- depositTokens: [
16115
- Global.getDefaultTokens().find((t) => t.symbol === "xSTRK"),
16116
- Global.getDefaultTokens().find((t) => t.symbol === "STRK")
16117
- ],
16118
- protocols: [_protocol2],
16119
- auditUrl: AUDIT_URL2,
16120
- maxTVL: Web3Number.fromWei("0", 18),
16121
- risk: {
16122
- riskFactor: _riskFactor2,
16123
- netRisk: _riskFactor2.reduce((acc, curr) => acc + curr.value * curr.weight, 0) / _riskFactor2.reduce((acc, curr) => acc + curr.weight, 0),
16124
- notARisks: getNoRiskTags(_riskFactor2)
16125
- },
16126
- apyMethodology: "APY based on 7-day historical performance, including fees and rewards.",
16127
- additionalInfo: {
16128
- newBounds: {
16129
- lower: -1,
16130
- upper: 1
16131
- },
16132
- lstContract: ContractAddr.from(
16133
- "0x028d709c875c0ceac3dce7065bec5328186dc89fe254527084d1689910954b0a"
16134
- ),
16135
- feeBps: 1e3,
16136
- rebalanceConditions: {
16137
- customShouldRebalance: async (currentPrice) => true,
16138
- minWaitHours: 24,
16139
- direction: "uponly"
16091
+ var xSTRKSTRK = {
16092
+ name: "Ekubo xSTRK/STRK",
16093
+ description: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
16094
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { children: _description2.replace("{{POOL_NAME}}", "xSTRK/STRK") }),
16095
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
16096
+ "ul",
16097
+ {
16098
+ style: {
16099
+ marginLeft: "20px",
16100
+ listStyle: "circle",
16101
+ fontSize: "12px"
16102
+ },
16103
+ children: [
16104
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("li", { style: { marginTop: "10px" }, children: "During withdrawal, you may receive either or both tokens depending on market conditions and prevailing prices." }),
16105
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("li", { style: { marginTop: "10px" }, children: "Sometimes you might see a negative APY \u2014 this is usually not a big deal. It happens when xSTRK's price drops on DEXes, but things typically bounce back within a few days or a week." })
16106
+ ]
16140
16107
  }
16108
+ )
16109
+ ] }),
16110
+ address: ContractAddr.from(
16111
+ "0x01f083b98674bc21effee29ef443a00c7b9a500fd92cf30341a3da12c73f2324"
16112
+ ),
16113
+ launchBlock: 1209881,
16114
+ type: "Other",
16115
+ // must be same order as poolKey token0 and token1
16116
+ depositTokens: [
16117
+ Global.getDefaultTokens().find((t) => t.symbol === "xSTRK"),
16118
+ Global.getDefaultTokens().find((t) => t.symbol === "STRK")
16119
+ ],
16120
+ protocols: [_protocol2],
16121
+ auditUrl: AUDIT_URL2,
16122
+ maxTVL: Web3Number.fromWei("0", 18),
16123
+ risk: {
16124
+ riskFactor: _riskFactor2,
16125
+ netRisk: _riskFactor2.reduce((acc, curr) => acc + curr.value * curr.weight, 0) / _riskFactor2.reduce((acc, curr) => acc + curr.weight, 0),
16126
+ notARisks: getNoRiskTags(_riskFactor2)
16127
+ },
16128
+ apyMethodology: "APY based on 7-day historical performance, including fees and rewards.",
16129
+ additionalInfo: {
16130
+ newBounds: {
16131
+ lower: -1,
16132
+ upper: 1
16141
16133
  },
16142
- faqs: [
16143
- ...faqs2,
16144
- {
16145
- question: "Why might I see a negative APY?",
16146
- answer: "A negative APY can occur when xSTRK's price drops on DEXes. This is usually temporary and tends to recover within a few days or a week."
16147
- }
16148
- ],
16149
- points: [{
16150
- multiplier: 1,
16151
- logo: "https://endur.fi/favicon.ico",
16152
- toolTip: "This strategy holds xSTRK and STRK tokens. Earn 1x Endur points on your xSTRK portion of Liquidity. STRK portion will earn Endur's DEX Bonus points. Points can be found on endur.fi."
16153
- }]
16134
+ lstContract: ContractAddr.from(
16135
+ "0x028d709c875c0ceac3dce7065bec5328186dc89fe254527084d1689910954b0a"
16136
+ ),
16137
+ feeBps: 1e3,
16138
+ rebalanceConditions: {
16139
+ customShouldRebalance: async (currentPrice) => true,
16140
+ minWaitHours: 24,
16141
+ direction: "uponly"
16142
+ }
16154
16143
  },
16144
+ faqs: [
16145
+ ...faqs2,
16146
+ {
16147
+ question: "Why might I see a negative APY?",
16148
+ answer: "A negative APY can occur when xSTRK's price drops on DEXes. This is usually temporary and tends to recover within a few days or a week."
16149
+ }
16150
+ ],
16151
+ points: [{
16152
+ multiplier: 1,
16153
+ logo: "https://endur.fi/favicon.ico",
16154
+ toolTip: "This strategy holds xSTRK and STRK tokens. Earn 1x Endur points on your xSTRK portion of Liquidity. STRK portion will earn Endur's DEX Bonus points. Points can be found on endur.fi."
16155
+ }]
16156
+ };
16157
+ var EkuboCLVaultStrategies = [
16158
+ xSTRKSTRK,
16155
16159
  {
16156
16160
  name: "Ekubo USDC/USDT",
16157
16161
  description: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
@@ -16205,6 +16209,47 @@ var EkuboCLVaultStrategies = [
16205
16209
  },
16206
16210
  faqs: [...faqs2]
16207
16211
  }
16212
+ // {
16213
+ // ...xSTRKSTRK,
16214
+ // name: "Ekubo STRK/USDC",
16215
+ // description: (
16216
+ // <div>
16217
+ // <p>{_description.replace("{{POOL_NAME}}", "STRK/USDC")}</p>
16218
+ // <ul
16219
+ // style={{
16220
+ // marginLeft: "20px",
16221
+ // listStyle: "circle",
16222
+ // fontSize: "12px",
16223
+ // }}
16224
+ // >
16225
+ // <li style={{ marginTop: "10px" }}>
16226
+ // During withdrawal, you may receive either or both tokens depending
16227
+ // on market conditions and prevailing prices.
16228
+ // </li>
16229
+ // </ul>
16230
+ // </div>
16231
+ // ),
16232
+ // address: ContractAddr.from(
16233
+ // "0xb7bd37121041261446d8eedec618955a4490641034942da688e8cbddea7b23"
16234
+ // ),
16235
+ // launchBlock: 1492136,
16236
+ // // must be same order as poolKey token0 and token1
16237
+ // depositTokens: [
16238
+ // Global.getDefaultTokens().find((t) => t.symbol === "STRK")!,
16239
+ // Global.getDefaultTokens().find((t) => t.symbol === "USDC")!,
16240
+ // ],
16241
+ // maxTVL: Web3Number.fromWei("0", 6),
16242
+ // additionalInfo: {
16243
+ // newBounds: "Managed by Re7",
16244
+ // feeBps: 1000,
16245
+ // rebalanceConditions: {
16246
+ // customShouldRebalance: async (currentPrice: number) =>
16247
+ // true,
16248
+ // minWaitHours: 6,
16249
+ // direction: "any",
16250
+ // },
16251
+ // },
16252
+ // },
16208
16253
  ];
16209
16254
 
16210
16255
  // src/notifs/telegram.ts