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