@strkfarm/sdk 1.0.45 → 1.0.46

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.
@@ -15296,7 +15296,7 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
15296
15296
  };
15297
15297
  }
15298
15298
  static div2Power128(num5) {
15299
- return Number(BigInt(num5.toString()) * 1000000n / BigInt(2 ** 128)) / 1e6;
15299
+ return Number(BigInt(num5.toString()) * BigInt(1e18) / BigInt(2 ** 128)) / 1e18;
15300
15300
  }
15301
15301
  static priceToTick(price, isRoundDown, tickSpacing) {
15302
15302
  const value = isRoundDown ? Math.floor(Math.log(price) / Math.log(1.000001)) : Math.ceil(Math.log(price) / Math.log(1.000001));
@@ -15317,18 +15317,15 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
15317
15317
  tick_spacing: result.pool_key.tick_spacing.toString(),
15318
15318
  extension: result.pool_key.extension.toString()
15319
15319
  };
15320
- const token0Info = await Global.getTokenInfoFromAddr(poolKey.token0);
15321
- const token1Info = await Global.getTokenInfoFromAddr(poolKey.token1);
15322
- assert(
15323
- token0Info.decimals == token1Info.decimals,
15324
- "Tested only for equal decimals"
15325
- );
15326
15320
  this.poolKey = poolKey;
15327
15321
  return poolKey;
15328
15322
  }
15329
15323
  async getNewBounds() {
15330
15324
  const poolKey = await this.getPoolKey();
15331
15325
  const currentPrice = await this._getCurrentPrice(poolKey);
15326
+ if (typeof this.metadata.additionalInfo.newBounds === "string") {
15327
+ throw new Error(`New bounds are managed known, to be set manually/externally`);
15328
+ }
15332
15329
  const newLower = currentPrice.tick + Number(this.metadata.additionalInfo.newBounds.lower) * Number(poolKey.tick_spacing);
15333
15330
  const newUpper = currentPrice.tick + Number(this.metadata.additionalInfo.newBounds.upper) * Number(poolKey.tick_spacing);
15334
15331
  return {
@@ -15343,8 +15340,8 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
15343
15340
  * @param amount1: amount of token1
15344
15341
  * @returns {amount0, amount1}
15345
15342
  */
15346
- async _getExpectedAmountsForLiquidity(amount0, amount1, bounds, justUseInputAmount = true) {
15347
- assert(amount0.greaterThan(0) || amount1.greaterThan(0), "Amount is 0");
15343
+ async _getExpectedAmountsForLiquidity(inputAmount0, inputAmount1, bounds, justUseInputAmount = true) {
15344
+ assert(inputAmount0.greaterThan(0) || inputAmount1.greaterThan(0), "Amount is 0");
15348
15345
  const sampleLiq = 1e20;
15349
15346
  const { amount0: sampleAmount0, amount1: sampleAmount1 } = await this.getLiquidityToAmounts(
15350
15347
  Web3Number.fromWei(sampleLiq.toString(), 18),
@@ -15358,39 +15355,37 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
15358
15355
  logger.verbose(
15359
15356
  `${_EkuboCLVault.name}: _getExpectedAmountsForLiquidity => price: ${price}`
15360
15357
  );
15361
- if (amount1.eq(0) && amount0.greaterThan(0)) {
15358
+ if (inputAmount1.eq(0) && inputAmount0.greaterThan(0)) {
15362
15359
  if (sampleAmount1.eq(0)) {
15363
15360
  return {
15364
- amount0,
15365
- amount1: Web3Number.fromWei("0", amount1.decimals),
15361
+ amount0: inputAmount0,
15362
+ amount1: Web3Number.fromWei("0", inputAmount1.decimals),
15366
15363
  ratio: Infinity
15367
15364
  };
15368
15365
  } else if (sampleAmount0.eq(0)) {
15369
15366
  return {
15370
- amount0: Web3Number.fromWei("0", amount0.decimals),
15371
- amount1: amount0.multipliedBy(price),
15367
+ amount0: Web3Number.fromWei("0", inputAmount0.decimals),
15368
+ // to ensure decimal consistency, we start with 0
15369
+ amount1: Web3Number.fromWei("0", inputAmount1.decimals).plus(inputAmount0.toString()).multipliedBy(price),
15372
15370
  ratio: 0
15373
15371
  };
15374
15372
  }
15375
- } else if (amount0.eq(0) && amount1.greaterThan(0)) {
15373
+ } else if (inputAmount0.eq(0) && inputAmount1.greaterThan(0)) {
15376
15374
  if (sampleAmount0.eq(0)) {
15377
15375
  return {
15378
- amount0: Web3Number.fromWei("0", amount0.decimals),
15379
- amount1,
15376
+ amount0: Web3Number.fromWei("0", inputAmount0.decimals),
15377
+ amount1: inputAmount1,
15380
15378
  ratio: 0
15381
15379
  };
15382
15380
  } else if (sampleAmount1.eq(0)) {
15383
15381
  return {
15384
- amount0: amount1.dividedBy(price),
15385
- amount1: Web3Number.fromWei("0", amount1.decimals),
15382
+ // to ensure decimal consistency, we start with 0
15383
+ amount0: Web3Number.fromWei("0", inputAmount0.decimals).plus(inputAmount1.toString()).dividedBy(price),
15384
+ amount1: Web3Number.fromWei("0", inputAmount1.decimals),
15386
15385
  ratio: Infinity
15387
15386
  };
15388
15387
  }
15389
15388
  }
15390
- assert(
15391
- sampleAmount0.decimals == sampleAmount1.decimals,
15392
- "Sample amounts have different decimals"
15393
- );
15394
15389
  const ratioWeb3Number = sampleAmount0.multipliedBy(1e18).dividedBy(sampleAmount1.toString()).dividedBy(1e18);
15395
15390
  const ratio = Number(ratioWeb3Number.toFixed(18));
15396
15391
  logger.verbose(
@@ -15398,23 +15393,23 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
15398
15393
  );
15399
15394
  if (justUseInputAmount)
15400
15395
  return this._solveExpectedAmountsEq(
15401
- amount0,
15402
- amount1,
15396
+ inputAmount0,
15397
+ inputAmount1,
15403
15398
  ratioWeb3Number,
15404
15399
  price
15405
15400
  );
15406
- if (amount1.eq(0) && amount0.greaterThan(0)) {
15407
- const _amount1 = amount0.dividedBy(ratioWeb3Number);
15401
+ if (inputAmount1.eq(0) && inputAmount0.greaterThan(0)) {
15402
+ const _amount1 = new Web3Number(inputAmount0.toString(), inputAmount1.decimals).dividedBy(ratioWeb3Number);
15408
15403
  return {
15409
- amount0,
15404
+ amount0: inputAmount0,
15410
15405
  amount1: _amount1,
15411
15406
  ratio
15412
15407
  };
15413
- } else if (amount0.eq(0) && amount1.greaterThan(0)) {
15414
- const _amount0 = amount1.multipliedBy(ratio);
15408
+ } else if (inputAmount0.eq(0) && inputAmount1.greaterThan(0)) {
15409
+ const _amount0 = new Web3Number(inputAmount1.toString(), inputAmount0.decimals).multipliedBy(ratio);
15415
15410
  return {
15416
15411
  amount0: _amount0,
15417
- amount1,
15412
+ amount1: inputAmount1,
15418
15413
  ratio
15419
15414
  };
15420
15415
  } else {
@@ -15477,7 +15472,7 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
15477
15472
  }
15478
15473
  };
15479
15474
  }
15480
- async getSwapInfoToHandleUnused(considerRebalance = true) {
15475
+ async getSwapInfoToHandleUnused(considerRebalance = true, newBounds = null) {
15481
15476
  const poolKey = await this.getPoolKey();
15482
15477
  const unusedBalances = await this.unusedBalances(poolKey);
15483
15478
  const { amount: token0Bal1, usdValue: token0PriceUsd } = unusedBalances.token0;
@@ -15500,7 +15495,9 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
15500
15495
  `${_EkuboCLVault.name}: getSwapInfoToHandleUnused => token0Bal: ${token0Bal.toString()}, token1Bal: ${token1Bal.toString()}`
15501
15496
  );
15502
15497
  let ekuboBounds;
15503
- if (considerRebalance) {
15498
+ if (newBounds) {
15499
+ ekuboBounds = newBounds;
15500
+ } else if (considerRebalance) {
15504
15501
  ekuboBounds = await this.getNewBounds();
15505
15502
  } else {
15506
15503
  ekuboBounds = await this.getCurrentBounds();
@@ -15741,6 +15738,10 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
15741
15738
  return BigInt(Math.floor(Math.sqrt(price) * 10 ** 9)) * BigInt(2 ** 128) / BigInt(1e9);
15742
15739
  }
15743
15740
  static i129ToNumber(i129) {
15741
+ if (i129.sign == 0 || i129.sign == 1) {
15742
+ return _EkuboCLVault.i129ToNumber({ mag: i129.mag, sign: i129.sign == 1 ? "true" : "false" });
15743
+ }
15744
+ assert(i129.sign.toString() == "false" || i129.sign.toString() == "true", "Invalid sign value");
15744
15745
  return i129.mag * (i129.sign.toString() == "false" ? 1n : -1n);
15745
15746
  }
15746
15747
  static tickToPrice(tick) {
@@ -15919,7 +15920,7 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
15919
15920
  subItems: [
15920
15921
  {
15921
15922
  key: "Range selection",
15922
- value: `${this.metadata.additionalInfo.newBounds.lower * Number(poolKey.tick_spacing)} to ${this.metadata.additionalInfo.newBounds.upper * Number(poolKey.tick_spacing)} ticks`
15923
+ 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`
15923
15924
  }
15924
15925
  ],
15925
15926
  linkedFlows: [linkedFlow],
@@ -15971,73 +15972,74 @@ var faqs2 = [
15971
15972
  ] })
15972
15973
  }
15973
15974
  ];
15974
- var EkuboCLVaultStrategies = [
15975
- {
15976
- name: "Ekubo xSTRK/STRK",
15977
- description: /* @__PURE__ */ jsxs2("div", { children: [
15978
- /* @__PURE__ */ jsx2("p", { children: _description2.replace("{{POOL_NAME}}", "xSTRK/STRK") }),
15979
- /* @__PURE__ */ jsxs2(
15980
- "ul",
15981
- {
15982
- style: {
15983
- marginLeft: "20px",
15984
- listStyle: "circle",
15985
- fontSize: "12px"
15986
- },
15987
- children: [
15988
- /* @__PURE__ */ jsx2("li", { style: { marginTop: "10px" }, children: "During withdrawal, you may receive either or both tokens depending on market conditions and prevailing prices." }),
15989
- /* @__PURE__ */ jsx2("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." })
15990
- ]
15991
- }
15992
- )
15993
- ] }),
15994
- address: ContractAddr.from(
15995
- "0x01f083b98674bc21effee29ef443a00c7b9a500fd92cf30341a3da12c73f2324"
15996
- ),
15997
- launchBlock: 1209881,
15998
- type: "Other",
15999
- // must be same order as poolKey token0 and token1
16000
- depositTokens: [
16001
- Global.getDefaultTokens().find((t) => t.symbol === "xSTRK"),
16002
- Global.getDefaultTokens().find((t) => t.symbol === "STRK")
16003
- ],
16004
- protocols: [_protocol2],
16005
- auditUrl: AUDIT_URL2,
16006
- maxTVL: Web3Number.fromWei("0", 18),
16007
- risk: {
16008
- riskFactor: _riskFactor2,
16009
- netRisk: _riskFactor2.reduce((acc, curr) => acc + curr.value * curr.weight, 0) / _riskFactor2.reduce((acc, curr) => acc + curr.weight, 0),
16010
- notARisks: getNoRiskTags(_riskFactor2)
16011
- },
16012
- apyMethodology: "APY based on 7-day historical performance, including fees and rewards.",
16013
- additionalInfo: {
16014
- newBounds: {
16015
- lower: -1,
16016
- upper: 1
16017
- },
16018
- lstContract: ContractAddr.from(
16019
- "0x028d709c875c0ceac3dce7065bec5328186dc89fe254527084d1689910954b0a"
16020
- ),
16021
- feeBps: 1e3,
16022
- rebalanceConditions: {
16023
- customShouldRebalance: async (currentPrice) => true,
16024
- minWaitHours: 24,
16025
- direction: "uponly"
16026
- }
15975
+ var xSTRKSTRK = {
15976
+ name: "Ekubo xSTRK/STRK",
15977
+ description: /* @__PURE__ */ jsxs2("div", { children: [
15978
+ /* @__PURE__ */ jsx2("p", { children: _description2.replace("{{POOL_NAME}}", "xSTRK/STRK") }),
15979
+ /* @__PURE__ */ jsxs2(
15980
+ "ul",
15981
+ {
15982
+ style: {
15983
+ marginLeft: "20px",
15984
+ listStyle: "circle",
15985
+ fontSize: "12px"
15986
+ },
15987
+ children: [
15988
+ /* @__PURE__ */ jsx2("li", { style: { marginTop: "10px" }, children: "During withdrawal, you may receive either or both tokens depending on market conditions and prevailing prices." }),
15989
+ /* @__PURE__ */ jsx2("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." })
15990
+ ]
15991
+ }
15992
+ )
15993
+ ] }),
15994
+ address: ContractAddr.from(
15995
+ "0x01f083b98674bc21effee29ef443a00c7b9a500fd92cf30341a3da12c73f2324"
15996
+ ),
15997
+ launchBlock: 1209881,
15998
+ type: "Other",
15999
+ // must be same order as poolKey token0 and token1
16000
+ depositTokens: [
16001
+ Global.getDefaultTokens().find((t) => t.symbol === "xSTRK"),
16002
+ Global.getDefaultTokens().find((t) => t.symbol === "STRK")
16003
+ ],
16004
+ protocols: [_protocol2],
16005
+ auditUrl: AUDIT_URL2,
16006
+ maxTVL: Web3Number.fromWei("0", 18),
16007
+ risk: {
16008
+ riskFactor: _riskFactor2,
16009
+ netRisk: _riskFactor2.reduce((acc, curr) => acc + curr.value * curr.weight, 0) / _riskFactor2.reduce((acc, curr) => acc + curr.weight, 0),
16010
+ notARisks: getNoRiskTags(_riskFactor2)
16011
+ },
16012
+ apyMethodology: "APY based on 7-day historical performance, including fees and rewards.",
16013
+ additionalInfo: {
16014
+ newBounds: {
16015
+ lower: -1,
16016
+ upper: 1
16027
16017
  },
16028
- faqs: [
16029
- ...faqs2,
16030
- {
16031
- question: "Why might I see a negative APY?",
16032
- 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."
16033
- }
16034
- ],
16035
- points: [{
16036
- multiplier: 1,
16037
- logo: "https://endur.fi/favicon.ico",
16038
- 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."
16039
- }]
16018
+ lstContract: ContractAddr.from(
16019
+ "0x028d709c875c0ceac3dce7065bec5328186dc89fe254527084d1689910954b0a"
16020
+ ),
16021
+ feeBps: 1e3,
16022
+ rebalanceConditions: {
16023
+ customShouldRebalance: async (currentPrice) => true,
16024
+ minWaitHours: 24,
16025
+ direction: "uponly"
16026
+ }
16040
16027
  },
16028
+ faqs: [
16029
+ ...faqs2,
16030
+ {
16031
+ question: "Why might I see a negative APY?",
16032
+ 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."
16033
+ }
16034
+ ],
16035
+ points: [{
16036
+ multiplier: 1,
16037
+ logo: "https://endur.fi/favicon.ico",
16038
+ 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."
16039
+ }]
16040
+ };
16041
+ var EkuboCLVaultStrategies = [
16042
+ xSTRKSTRK,
16041
16043
  {
16042
16044
  name: "Ekubo USDC/USDT",
16043
16045
  description: /* @__PURE__ */ jsxs2("div", { children: [
@@ -16091,6 +16093,47 @@ var EkuboCLVaultStrategies = [
16091
16093
  },
16092
16094
  faqs: [...faqs2]
16093
16095
  }
16096
+ // {
16097
+ // ...xSTRKSTRK,
16098
+ // name: "Ekubo STRK/USDC",
16099
+ // description: (
16100
+ // <div>
16101
+ // <p>{_description.replace("{{POOL_NAME}}", "STRK/USDC")}</p>
16102
+ // <ul
16103
+ // style={{
16104
+ // marginLeft: "20px",
16105
+ // listStyle: "circle",
16106
+ // fontSize: "12px",
16107
+ // }}
16108
+ // >
16109
+ // <li style={{ marginTop: "10px" }}>
16110
+ // During withdrawal, you may receive either or both tokens depending
16111
+ // on market conditions and prevailing prices.
16112
+ // </li>
16113
+ // </ul>
16114
+ // </div>
16115
+ // ),
16116
+ // address: ContractAddr.from(
16117
+ // "0xb7bd37121041261446d8eedec618955a4490641034942da688e8cbddea7b23"
16118
+ // ),
16119
+ // launchBlock: 1492136,
16120
+ // // must be same order as poolKey token0 and token1
16121
+ // depositTokens: [
16122
+ // Global.getDefaultTokens().find((t) => t.symbol === "STRK")!,
16123
+ // Global.getDefaultTokens().find((t) => t.symbol === "USDC")!,
16124
+ // ],
16125
+ // maxTVL: Web3Number.fromWei("0", 6),
16126
+ // additionalInfo: {
16127
+ // newBounds: "Managed by Re7",
16128
+ // feeBps: 1000,
16129
+ // rebalanceConditions: {
16130
+ // customShouldRebalance: async (currentPrice: number) =>
16131
+ // true,
16132
+ // minWaitHours: 6,
16133
+ // direction: "any",
16134
+ // },
16135
+ // },
16136
+ // },
16094
16137
  ];
16095
16138
  export {
16096
16139
  AutoCompounderSTRK,
package/dist/index.d.ts CHANGED
@@ -600,7 +600,7 @@ interface CLVaultStrategySettings {
600
600
  newBounds: {
601
601
  lower: number;
602
602
  upper: number;
603
- };
603
+ } | string;
604
604
  lstContract?: ContractAddr;
605
605
  truePrice?: number;
606
606
  feeBps: number;
@@ -695,7 +695,7 @@ declare class EkuboCLVault extends BaseStrategy<DualTokenInfo, DualActionAmount>
695
695
  usdValue: number;
696
696
  };
697
697
  }>;
698
- getSwapInfoToHandleUnused(considerRebalance?: boolean): Promise<SwapInfo>;
698
+ getSwapInfoToHandleUnused(considerRebalance?: boolean, newBounds?: EkuboBounds | null): Promise<SwapInfo>;
699
699
  getSwapInfoGivenAmounts(poolKey: EkuboPoolKey, token0Bal: Web3Number, token1Bal: Web3Number, bounds: EkuboBounds): Promise<SwapInfo>;
700
700
  /**
701
701
  * Attempts to rebalance the vault by iteratively adjusting swap amounts if initial attempt fails.
@@ -718,7 +718,7 @@ declare class EkuboCLVault extends BaseStrategy<DualTokenInfo, DualActionAmount>
718
718
  static priceToSqrtRatio(price: number): bigint;
719
719
  static i129ToNumber(i129: {
720
720
  mag: bigint;
721
- sign: number;
721
+ sign: 0 | 1 | "true" | "false";
722
722
  }): bigint;
723
723
  static tickToPrice(tick: bigint): number;
724
724
  getLiquidityToAmounts(liquidity: Web3Number, bounds: EkuboBounds, blockIdentifier?: BlockIdentifier, _poolKey?: EkuboPoolKey | null, _currentPrice?: {