@strkfarm/sdk 2.0.0-staging.69 → 2.0.0-staging.70

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.
@@ -27939,6 +27939,7 @@ ${JSON.stringify(data, null, 2)}`;
27939
27939
  PRICE_ROUTER: () => PRICE_ROUTER,
27940
27940
  Pragma: () => Pragma,
27941
27941
  Pricer: () => Pricer,
27942
+ PricerAvnuApi: () => PricerAvnuApi,
27942
27943
  PricerFromApi: () => PricerFromApi,
27943
27944
  PricerLST: () => PricerLST,
27944
27945
  Protocols: () => Protocols,
@@ -73071,8 +73072,9 @@ ${JSON.stringify(data, null, 2)}`;
73071
73072
  decimals: 18,
73072
73073
  coingeckId: void 0,
73073
73074
  displayDecimals: 6,
73074
- priceCheckAmount: 1e-4
73075
+ priceCheckAmount: 1e-4,
73075
73076
  // 112000 * 0.0001 = $11.2
73077
+ dontPrice: true
73076
73078
  }, {
73077
73079
  name: "mRe7YIELD",
73078
73080
  symbol: "mRe7YIELD",
@@ -73081,7 +73083,8 @@ ${JSON.stringify(data, null, 2)}`;
73081
73083
  decimals: 18,
73082
73084
  coingeckId: void 0,
73083
73085
  displayDecimals: 2,
73084
- priceCheckAmount: 100
73086
+ priceCheckAmount: 100,
73087
+ dontPrice: true
73085
73088
  }, {
73086
73089
  name: "fyeWBTC",
73087
73090
  symbol: "fyeWBTC",
@@ -73090,8 +73093,9 @@ ${JSON.stringify(data, null, 2)}`;
73090
73093
  decimals: 8,
73091
73094
  coingeckId: void 0,
73092
73095
  displayDecimals: 6,
73093
- priceCheckAmount: 1e-3
73096
+ priceCheckAmount: 1e-3,
73094
73097
  // 112000 * 0.0001 = $110.2
73098
+ dontPrice: true
73095
73099
  }, {
73096
73100
  name: "fyETH",
73097
73101
  symbol: "fyETH",
@@ -73100,7 +73104,8 @@ ${JSON.stringify(data, null, 2)}`;
73100
73104
  decimals: 18,
73101
73105
  coingeckId: void 0,
73102
73106
  displayDecimals: 4,
73103
- priceCheckAmount: 0.1
73107
+ priceCheckAmount: 0.1,
73108
+ dontPrice: true
73104
73109
  }, {
73105
73110
  name: "fyeUSDC",
73106
73111
  symbol: "fyeUSDC",
@@ -73109,7 +73114,8 @@ ${JSON.stringify(data, null, 2)}`;
73109
73114
  decimals: 6,
73110
73115
  coingeckId: void 0,
73111
73116
  displayDecimals: 2,
73112
- priceCheckAmount: 100
73117
+ priceCheckAmount: 100,
73118
+ dontPrice: true
73113
73119
  }, {
73114
73120
  name: "strkBTC",
73115
73121
  symbol: "strkBTC",
@@ -75869,7 +75875,95 @@ ${JSON.stringify(data, null, 2)}`;
75869
75875
  }
75870
75876
  };
75871
75877
 
75878
+ // src/modules/pricer-avnu-api.ts
75879
+ var AVNU_TOKENS_API = "https://starknet.impulse.avnu.fi/v3/tokens";
75880
+ var PricerAvnuApi = class extends PricerBase {
75881
+ constructor(config3, tokens2) {
75882
+ super(config3, tokens2);
75883
+ this.prices = {};
75884
+ this.refreshInterval = 15e3;
75885
+ this.staleTime = 5 * 60 * 1e3;
75886
+ this.pollTimer = null;
75887
+ this.loading = false;
75888
+ }
75889
+ start() {
75890
+ this._loadPrices();
75891
+ this.pollTimer = setInterval(() => {
75892
+ this._loadPrices();
75893
+ }, this.refreshInterval);
75894
+ }
75895
+ stop() {
75896
+ if (this.pollTimer) {
75897
+ clearInterval(this.pollTimer);
75898
+ this.pollTimer = null;
75899
+ }
75900
+ }
75901
+ isStale(timestamp) {
75902
+ return Date.now() - timestamp.getTime() > this.staleTime;
75903
+ }
75904
+ hasPrice(tokenSymbol) {
75905
+ const info = this.prices[tokenSymbol];
75906
+ return !!info && !this.isStale(info.timestamp);
75907
+ }
75908
+ async getPrice(tokenSymbol) {
75909
+ const info = this.prices[tokenSymbol];
75910
+ if (!info) {
75911
+ throw new Error(`AvnuApi: price of ${tokenSymbol} not found`);
75912
+ }
75913
+ if (this.isStale(info.timestamp)) {
75914
+ throw new Error(`AvnuApi: price of ${tokenSymbol} is stale`);
75915
+ }
75916
+ return info;
75917
+ }
75918
+ async _loadPrices() {
75919
+ if (this.loading) {
75920
+ return;
75921
+ }
75922
+ this.loading = true;
75923
+ const timestamp = /* @__PURE__ */ new Date();
75924
+ try {
75925
+ const result2 = await axios_default.get(AVNU_TOKENS_API);
75926
+ const priceByAddress = /* @__PURE__ */ new Map();
75927
+ for (const entry of result2.data) {
75928
+ const usd = entry.starknet?.usd;
75929
+ if (usd != null && usd > 0) {
75930
+ priceByAddress.set(ContractAddr.standardise(entry.address), usd);
75931
+ }
75932
+ }
75933
+ for (const token of this.tokens) {
75934
+ if (token.symbol === "USDT" || token.symbol === "USDC") {
75935
+ this.prices[token.symbol] = { price: 1, timestamp };
75936
+ continue;
75937
+ }
75938
+ const targetToken = token.priceProxySymbol ? this.tokens.find((t) => t.symbol === token.priceProxySymbol) : token;
75939
+ if (!targetToken) {
75940
+ continue;
75941
+ }
75942
+ const addr = targetToken.address.address;
75943
+ const price = priceByAddress.get(addr);
75944
+ if (price != null) {
75945
+ this.prices[token.symbol] = { price, timestamp };
75946
+ logger2.verbose(
75947
+ `AvnuApi: ${token.symbol} -> $${price}`
75948
+ );
75949
+ }
75950
+ }
75951
+ } catch (error2) {
75952
+ logger2.warn(`AvnuApi: failed to fetch tokens: ${error2?.message ?? error2}`);
75953
+ } finally {
75954
+ this.loading = false;
75955
+ }
75956
+ }
75957
+ };
75958
+
75872
75959
  // src/modules/pricer.ts
75960
+ var PRICE_METHOD_PRIORITY = [
75961
+ "AvnuApi",
75962
+ "Coinbase",
75963
+ "Coinmarketcap",
75964
+ "Ekubo",
75965
+ "Avnu"
75966
+ ];
75873
75967
  var Pricer = class extends PricerBase {
75874
75968
  // e.g. ETH/USDC
75875
75969
  constructor(config3, tokens2, refreshInterval = 3e4, staleTime = 6e4) {
@@ -75888,6 +75982,7 @@ ${JSON.stringify(data, null, 2)}`;
75888
75982
  this.EKUBO_API = "https://prod-api-quoter.ekubo.org/23448594291968334/{{AMOUNT}}/{{TOKEN_ADDRESS}}/0x033068F6539f8e6e6b131e6B2B814e6c34A5224bC66947c47DaB9dFeE93b35fb";
75889
75983
  this.refreshInterval = refreshInterval;
75890
75984
  this.staleTime = staleTime;
75985
+ this.avnuApiPricer = new PricerAvnuApi(config3, tokens2);
75891
75986
  }
75892
75987
  isReady() {
75893
75988
  const allPricesExist = Object.keys(this.prices).length === this.tokens.length;
@@ -75917,6 +76012,7 @@ ${JSON.stringify(data, null, 2)}`;
75917
76012
  });
75918
76013
  }
75919
76014
  start() {
76015
+ this.avnuApiPricer.start();
75920
76016
  this._loadPrices();
75921
76017
  setInterval(() => {
75922
76018
  this._loadPrices();
@@ -75941,6 +76037,9 @@ ${JSON.stringify(data, null, 2)}`;
75941
76037
  let retry = 0;
75942
76038
  while (retry < MAX_RETRIES) {
75943
76039
  try {
76040
+ if (token.dontPrice) {
76041
+ return;
76042
+ }
75944
76043
  if (token.symbol === "USDT" || token.symbol === "USDC") {
75945
76044
  this.prices[token.symbol] = {
75946
76045
  price: 1,
@@ -75988,51 +76087,52 @@ ${JSON.stringify(data, null, 2)}`;
75988
76087
  });
75989
76088
  }
75990
76089
  }
75991
- async _getPrice(token, defaultMethod = "all") {
75992
- const methodToUse = this.methodToUse[token.symbol] || defaultMethod;
75993
- logger2.verbose(`Fetching price of ${token.symbol} using ${methodToUse}`);
75994
- switch (methodToUse) {
76090
+ async _getPrice(token) {
76091
+ const pinned = this.methodToUse[token.symbol];
76092
+ if (pinned) {
76093
+ logger2.verbose(`Fetching price of ${token.symbol} using pinned ${pinned}`);
76094
+ try {
76095
+ return await this._tryPriceMethod(token, pinned);
76096
+ } catch (error2) {
76097
+ console.warn(`${pinned}: pinned price failed [${token.symbol}]: `, error2.message);
76098
+ delete this.methodToUse[token.symbol];
76099
+ }
76100
+ }
76101
+ for (const method of PRICE_METHOD_PRIORITY) {
76102
+ logger2.verbose(`Fetching price of ${token.symbol} using ${method}`);
76103
+ try {
76104
+ const result2 = await this._tryPriceMethod(token, method);
76105
+ this.methodToUse[token.symbol] = method;
76106
+ return result2;
76107
+ } catch (error2) {
76108
+ console.warn(`${method}: price err [${token.symbol}]: `, error2.message);
76109
+ }
76110
+ }
76111
+ throw new FatalError(`Price not found for ${token.symbol}`);
76112
+ }
76113
+ async _tryPriceMethod(token, method) {
76114
+ switch (method) {
76115
+ case "AvnuApi":
76116
+ return await this._getPriceAvnuApi(token);
75995
76117
  case "Coinbase":
75996
- // try {
75997
- // const result = await this._getPriceCoinbase(token);
75998
- // this.methodToUse[token.symbol] = 'Coinbase';
75999
- // return result;
76000
- // } catch (error: any) {
76001
- // console.warn(`Coinbase: price err: message [${token.symbol}]: `, error.message);
76002
- // // do nothing, try next
76003
- // }
76118
+ return await this._getPriceCoinbase(token);
76004
76119
  case "Coinmarketcap":
76005
- try {
76006
- const result2 = await this._getPriceCoinMarketCap(token);
76007
- this.methodToUse[token.symbol] = "Coinmarketcap";
76008
- return result2;
76009
- } catch (error2) {
76010
- console.warn(`CoinMarketCap: price err [${token.symbol}]: `, Object.keys(error2));
76011
- console.warn(`CoinMarketCap: price err [${token.symbol}]: `, error2.message);
76012
- }
76120
+ return await this._getPriceCoinMarketCap(token);
76013
76121
  case "Ekubo":
76014
- try {
76015
- const result2 = await this._getPriceEkubo(token, new Web3Number(token.priceCheckAmount ? token.priceCheckAmount : 1, token.decimals));
76016
- this.methodToUse[token.symbol] = "Ekubo";
76017
- return result2;
76018
- } catch (error2) {
76019
- console.warn(`Ekubo: price err [${token.symbol}]: `, error2.message);
76020
- console.warn(`Ekubo: price err [${token.symbol}]: `, Object.keys(error2));
76021
- }
76122
+ return await this._getPriceEkubo(
76123
+ token,
76124
+ new Web3Number(token.priceCheckAmount ? token.priceCheckAmount : 1, token.decimals)
76125
+ );
76022
76126
  case "Avnu":
76023
- try {
76024
- const result2 = await this._getAvnuPrice(token, new Web3Number(token.priceCheckAmount ? token.priceCheckAmount : 1, token.decimals));
76025
- this.methodToUse[token.symbol] = "Avnu";
76026
- return result2;
76027
- } catch (error2) {
76028
- console.warn(`Avnu: price err [${token.symbol}]: `, error2.message);
76029
- console.warn(`Avnu: price err [${token.symbol}]: `, Object.keys(error2));
76030
- }
76031
- }
76032
- if (defaultMethod == "all") {
76033
- return await this._getPrice(token, "Coinbase");
76127
+ return await this._getAvnuPrice(
76128
+ token,
76129
+ new Web3Number(token.priceCheckAmount ? token.priceCheckAmount : 1, token.decimals)
76130
+ );
76034
76131
  }
76035
- throw new FatalError(`Price not found for ${token.symbol}`);
76132
+ }
76133
+ async _getPriceAvnuApi(token) {
76134
+ const priceInfo = await this.avnuApiPricer.getPrice(token.symbol);
76135
+ return priceInfo.price;
76036
76136
  }
76037
76137
  async _getPriceCoinbase(token) {
76038
76138
  const url = this.PRICE_API.replace("{{PRICER_KEY}}", `${token.symbol}-USD`);
@@ -104339,7 +104439,7 @@ spurious results.`);
104339
104439
  const token0Usd = Number(amount0.toFixed(13)) * P0.price;
104340
104440
  const token1Usd = Number(amount1.toFixed(13)) * P1.price;
104341
104441
  const totalUsdValue = token0Usd + token1Usd;
104342
- if (totalUsdValue === 0 || token0Usd === 0 || token1Usd === 0 || amount0.eq(0) || amount1.eq(0)) {
104442
+ if ((totalUsdValue === 0 || token0Usd === 0 || token1Usd === 0 || amount0.eq(0) || amount1.eq(0)) && this.metadata.settings?.liveStatus === "Active" /* ACTIVE */) {
104343
104443
  logger2.warn(
104344
104444
  `${this.metadata.name}:getTVL - Zero value detected: usdValue=${totalUsdValue}, amount0=${amount0.toString()}, amount1=${amount1.toString()}, token0Price=${P0.price}, token1Price=${P1.price}, token0Usd=${token0Usd}, token1Usd=${token1Usd}`
104345
104445
  );
@@ -116454,7 +116554,7 @@ spurious results.`);
116454
116554
  sDec
116455
116555
  ).multipliedBy(secondaryTokenPrice.price);
116456
116556
  const totalUsdValue = primaryTokenUsd.plus(secondaryTokenUsd).toNumber();
116457
- if (totalUsdValue === 0 || primaryTokenAmount.eq(0) || secondaryTokenAmount.eq(0)) {
116557
+ if ((totalUsdValue === 0 || primaryTokenAmount.eq(0) || secondaryTokenAmount.eq(0)) && this.metadata.settings?.liveStatus === "Active" /* ACTIVE */) {
116458
116558
  logger2.warn(
116459
116559
  `${this.metadata.name}:getTVL - Zero value detected: usdValue=${totalUsdValue}, primaryTokenAmount=${primaryTokenAmount.toString()}, secondaryTokenAmount=${secondaryTokenAmount.toString()}, primaryTokenPrice=${primaryTokenPrice.price}, secondaryTokenPrice=${secondaryTokenPrice.price}, primaryTokenUsd=${primaryTokenUsd.toNumber()}, secondaryTokenUsd=${secondaryTokenUsd.toNumber()}`
116460
116560
  );
@@ -119809,7 +119909,7 @@ spurious results.`);
119809
119909
  this.metadata.depositTokens[0].symbol
119810
119910
  );
119811
119911
  const usdValue = Number(amount.toFixed(6)) * price.price;
119812
- if (usdValue === 0 || amount.eq(0)) {
119912
+ if ((usdValue === 0 || amount.eq(0)) && this.metadata.settings?.liveStatus === "Active" /* ACTIVE */) {
119813
119913
  logger2.warn(
119814
119914
  `${this.metadata.name}:getTVL - Zero value detected: usdValue=${usdValue}, amount=${amount.toString()}, price=${price.price}`
119815
119915
  );