@tokemak/queries 0.0.2 → 0.0.4

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.
Files changed (3) hide show
  1. package/dist/index.cjs +701 -408
  2. package/dist/index.d.ts +440 -98
  3. package/package.json +13 -13
package/dist/index.cjs CHANGED
@@ -645,7 +645,7 @@ var require_version = __commonJS({
645
645
  "use strict";
646
646
  Object.defineProperty(exports, "__esModule", { value: true });
647
647
  exports.version = void 0;
648
- exports.version = "6.14.4";
648
+ exports.version = "6.15.0";
649
649
  }
650
650
  });
651
651
 
@@ -5877,15 +5877,15 @@ var require_curve = __commonJS({
5877
5877
  const { windows, windowSize } = opts(W);
5878
5878
  const points = [];
5879
5879
  let p = elm;
5880
- let base3 = p;
5880
+ let base2 = p;
5881
5881
  for (let window2 = 0; window2 < windows; window2++) {
5882
- base3 = p;
5883
- points.push(base3);
5882
+ base2 = p;
5883
+ points.push(base2);
5884
5884
  for (let i = 1; i < windowSize; i++) {
5885
- base3 = base3.add(p);
5886
- points.push(base3);
5885
+ base2 = base2.add(p);
5886
+ points.push(base2);
5887
5887
  }
5888
- p = base3.double();
5888
+ p = base2.double();
5889
5889
  }
5890
5890
  return points;
5891
5891
  },
@@ -7412,13 +7412,29 @@ var require_signature = __commonJS({
7412
7412
  * The ``s`` value for a signature.
7413
7413
  */
7414
7414
  get s() {
7415
+ (0, index_js_2.assertArgument)(parseInt(__privateGet(this, _s).substring(0, 3)) < 8, "non-canonical s; use ._s", "s", __privateGet(this, _s));
7415
7416
  return __privateGet(this, _s);
7416
7417
  }
7417
7418
  set s(_value) {
7418
7419
  (0, index_js_2.assertArgument)((0, index_js_2.dataLength)(_value) === 32, "invalid s", "value", _value);
7419
- const value = (0, index_js_2.hexlify)(_value);
7420
- (0, index_js_2.assertArgument)(parseInt(value.substring(0, 3)) < 8, "non-canonical s", "value", value);
7421
- __privateSet(this, _s, value);
7420
+ __privateSet(this, _s, (0, index_js_2.hexlify)(_value));
7421
+ }
7422
+ /**
7423
+ * Return the s value, unchecked for EIP-2 compliance.
7424
+ *
7425
+ * This should generally not be used and is for situations where
7426
+ * a non-canonical S value might be relevant, such as Frontier blocks
7427
+ * that were mined prior to EIP-2 or invalid Authorization List
7428
+ * signatures.
7429
+ */
7430
+ get _s() {
7431
+ return __privateGet(this, _s);
7432
+ }
7433
+ /**
7434
+ * Returns true if the Signature is valid for [[link-eip-2]] signatures.
7435
+ */
7436
+ isValid() {
7437
+ return parseInt(__privateGet(this, _s).substring(0, 3)) < 8;
7422
7438
  }
7423
7439
  /**
7424
7440
  * The ``v`` value for a signature.
@@ -7488,13 +7504,13 @@ var require_signature = __commonJS({
7488
7504
  return (0, index_js_2.concat)([this.r, this.s, this.yParity ? "0x1c" : "0x1b"]);
7489
7505
  }
7490
7506
  [Symbol.for("nodejs.util.inspect.custom")]() {
7491
- return `Signature { r: "${this.r}", s: "${this.s}", yParity: ${this.yParity}, networkV: ${this.networkV} }`;
7507
+ return `Signature { r: "${this.r}", s: "${this._s}"${this.isValid() ? "" : ', valid: "false"'}, yParity: ${this.yParity}, networkV: ${this.networkV} }`;
7492
7508
  }
7493
7509
  /**
7494
7510
  * Returns a new identical [[Signature]].
7495
7511
  */
7496
7512
  clone() {
7497
- const clone = new _Signature(_guard, this.r, this.s, this.v);
7513
+ const clone = new _Signature(_guard, this.r, this._s, this.v);
7498
7514
  if (this.networkV) {
7499
7515
  __privateSet(clone, _networkV, this.networkV);
7500
7516
  }
@@ -7509,7 +7525,7 @@ var require_signature = __commonJS({
7509
7525
  _type: "signature",
7510
7526
  networkV: networkV != null ? networkV.toString() : null,
7511
7527
  r: this.r,
7512
- s: this.s,
7528
+ s: this._s,
7513
7529
  v: this.v
7514
7530
  };
7515
7531
  }
@@ -7607,10 +7623,9 @@ var require_signature = __commonJS({
7607
7623
  }
7608
7624
  if (bytes.length === 65) {
7609
7625
  const r2 = (0, index_js_2.hexlify)(bytes.slice(0, 32));
7610
- const s2 = bytes.slice(32, 64);
7611
- assertError((s2[0] & 128) === 0, "non-canonical s");
7626
+ const s2 = (0, index_js_2.hexlify)(bytes.slice(32, 64));
7612
7627
  const v2 = _Signature.getNormalizedV(bytes[64]);
7613
- return new _Signature(_guard, r2, (0, index_js_2.hexlify)(s2), v2);
7628
+ return new _Signature(_guard, r2, s2, v2);
7614
7629
  }
7615
7630
  assertError(false, "invalid raw signature length");
7616
7631
  }
@@ -7632,7 +7647,6 @@ var require_signature = __commonJS({
7632
7647
  }
7633
7648
  assertError(false, "missing s");
7634
7649
  }(sig.s, sig.yParityAndS);
7635
- assertError(((0, index_js_2.getBytes)(s)[0] & 128) == 0, "non-canonical s");
7636
7650
  const { networkV, v } = function(_v2, yParityAndS, yParity) {
7637
7651
  if (_v2 != null) {
7638
7652
  const v2 = (0, index_js_2.getBigInt)(_v2);
@@ -7980,7 +7994,7 @@ var require_address = __commonJS({
7980
7994
  }
7981
7995
  return result;
7982
7996
  }
7983
- function getAddress5(address) {
7997
+ function getAddress6(address) {
7984
7998
  (0, index_js_2.assertArgument)(typeof address === "string", "invalid address", "address", address);
7985
7999
  if (address.match(/^(0x)?[0-9a-fA-F]{40}$/)) {
7986
8000
  if (!address.startsWith("0x")) {
@@ -8000,9 +8014,9 @@ var require_address = __commonJS({
8000
8014
  }
8001
8015
  (0, index_js_2.assertArgument)(false, "invalid address", "address", address);
8002
8016
  }
8003
- exports.getAddress = getAddress5;
8017
+ exports.getAddress = getAddress6;
8004
8018
  function getIcapAddress(address) {
8005
- let base36 = BigInt(getAddress5(address)).toString(36).toUpperCase();
8019
+ let base36 = BigInt(getAddress6(address)).toString(36).toUpperCase();
8006
8020
  while (base36.length < 30) {
8007
8021
  base36 = "0" + base36;
8008
8022
  }
@@ -12018,14 +12032,14 @@ var require_typed_data = __commonJS({
12018
12032
  const types = {};
12019
12033
  Object.keys(_types2).forEach((type) => {
12020
12034
  types[type] = _types2[type].map(({ name, type: type2 }) => {
12021
- let { base: base3, index } = splitArray(type2);
12022
- if (base3 === "int" && !_types2["int"]) {
12023
- base3 = "int256";
12035
+ let { base: base2, index } = splitArray(type2);
12036
+ if (base2 === "int" && !_types2["int"]) {
12037
+ base2 = "int256";
12024
12038
  }
12025
- if (base3 === "uint" && !_types2["uint"]) {
12026
- base3 = "uint256";
12039
+ if (base2 === "uint" && !_types2["uint"]) {
12040
+ base2 = "uint256";
12027
12041
  }
12028
- return { name, type: base3 + (index || "") };
12042
+ return { name, type: base2 + (index || "") };
12029
12043
  });
12030
12044
  links.set(type, /* @__PURE__ */ new Set());
12031
12045
  parents.set(type, []);
@@ -43747,6 +43761,45 @@ var require_get_proto = __commonJS({
43747
43761
  }
43748
43762
  });
43749
43763
 
43764
+ // ../../node_modules/async-function/index.js
43765
+ var require_async_function = __commonJS({
43766
+ "../../node_modules/async-function/index.js"(exports, module2) {
43767
+ "use strict";
43768
+ var cached = (
43769
+ /** @type {import('.').AsyncFunctionConstructor} */
43770
+ async function() {
43771
+ }.constructor
43772
+ );
43773
+ module2.exports = () => cached;
43774
+ }
43775
+ });
43776
+
43777
+ // ../../node_modules/generator-function/index.js
43778
+ var require_generator_function = __commonJS({
43779
+ "../../node_modules/generator-function/index.js"(exports, module2) {
43780
+ "use strict";
43781
+ var cached = (
43782
+ /** @type {GeneratorFunctionConstructor} */
43783
+ function* () {
43784
+ }.constructor
43785
+ );
43786
+ module2.exports = () => cached;
43787
+ }
43788
+ });
43789
+
43790
+ // ../../node_modules/async-generator-function/index.js
43791
+ var require_async_generator_function = __commonJS({
43792
+ "../../node_modules/async-generator-function/index.js"(exports, module2) {
43793
+ "use strict";
43794
+ var cached = (
43795
+ /** @type {import('.').AsyncGeneratorFunctionConstructor} */
43796
+ async function* () {
43797
+ }.constructor
43798
+ );
43799
+ module2.exports = () => cached;
43800
+ }
43801
+ });
43802
+
43750
43803
  // ../../node_modules/hasown/index.js
43751
43804
  var require_hasown = __commonJS({
43752
43805
  "../../node_modules/hasown/index.js"(exports, module2) {
@@ -43778,13 +43831,6 @@ var require_get_intrinsic = __commonJS({
43778
43831
  var pow = require_pow();
43779
43832
  var round = require_round();
43780
43833
  var sign = require_sign();
43781
- var $Function = Function;
43782
- var getEvalledConstructor = function(expressionSyntax) {
43783
- try {
43784
- return $Function('"use strict"; return (' + expressionSyntax + ").constructor;")();
43785
- } catch (e) {
43786
- }
43787
- };
43788
43834
  var $gOPD = require_gopd();
43789
43835
  var $defineProperty = require_es_define_property();
43790
43836
  var throwTypeError = function() {
@@ -43840,7 +43886,7 @@ var require_get_intrinsic = __commonJS({
43840
43886
  "%Float32Array%": typeof Float32Array === "undefined" ? undefined2 : Float32Array,
43841
43887
  "%Float64Array%": typeof Float64Array === "undefined" ? undefined2 : Float64Array,
43842
43888
  "%FinalizationRegistry%": typeof FinalizationRegistry === "undefined" ? undefined2 : FinalizationRegistry,
43843
- "%Function%": $Function,
43889
+ "%Function%": Function,
43844
43890
  "%GeneratorFunction%": needsEval,
43845
43891
  "%Int8Array%": typeof Int8Array === "undefined" ? undefined2 : Int8Array,
43846
43892
  "%Int16Array%": typeof Int16Array === "undefined" ? undefined2 : Int16Array,
@@ -43903,14 +43949,17 @@ var require_get_intrinsic = __commonJS({
43903
43949
  }
43904
43950
  }
43905
43951
  var errorProto;
43952
+ var getAsyncFunction = require_async_function();
43953
+ var getGeneratorFunction = require_generator_function();
43954
+ var getAsyncGeneratorFunction = require_async_generator_function();
43906
43955
  var doEval = function doEval2(name) {
43907
43956
  var value;
43908
43957
  if (name === "%AsyncFunction%") {
43909
- value = getEvalledConstructor("async function () {}");
43958
+ value = getAsyncFunction() || void 0;
43910
43959
  } else if (name === "%GeneratorFunction%") {
43911
- value = getEvalledConstructor("function* () {}");
43960
+ value = getGeneratorFunction() || void 0;
43912
43961
  } else if (name === "%AsyncGeneratorFunction%") {
43913
- value = getEvalledConstructor("async function* () {}");
43962
+ value = getAsyncGeneratorFunction() || void 0;
43914
43963
  } else if (name === "%AsyncGenerator%") {
43915
43964
  var fn = doEval2("%AsyncGeneratorFunction%");
43916
43965
  if (fn) {
@@ -44963,8 +45012,8 @@ var require_follow_redirects = __commonJS({
44963
45012
  }
44964
45013
  return parsed;
44965
45014
  }
44966
- function resolveUrl(relative, base3) {
44967
- return useNativeURL ? new URL2(relative, base3) : parseUrl(url.resolve(base3, relative));
45015
+ function resolveUrl(relative, base2) {
45016
+ return useNativeURL ? new URL2(relative, base2) : parseUrl(url.resolve(base2, relative));
44968
45017
  }
44969
45018
  function validateUrl(input) {
44970
45019
  if (/^\[/.test(input.hostname) && !/^\[[:0-9a-f]+\]$/i.test(input.hostname)) {
@@ -52617,6 +52666,16 @@ var require_dist2 = __commonJS({
52617
52666
  systemName: "gen3",
52618
52667
  systemRegistry: "0x1a912EB51D3cF8364eBAEE5A982cA37f25aD8848"
52619
52668
  };
52669
+ var arbGen3Config = {
52670
+ chainId: 42161,
52671
+ systemName: "gen3",
52672
+ systemRegistry: "0xBFd8E6C9bF2CD5466f5651746f8E946A6C7b4220"
52673
+ };
52674
+ var plasmaGen3Config = {
52675
+ chainId: 9745,
52676
+ systemName: "gen3",
52677
+ systemRegistry: "0x9065C0E33Bc8FB31A21874f399985e39bC187D48"
52678
+ };
52620
52679
  function getConfigByRegistry(chainId, systemRegistry) {
52621
52680
  const cid = chainId.toString();
52622
52681
  const sysReg = systemRegistry.toLowerCase();
@@ -52626,6 +52685,10 @@ var require_dist2 = __commonJS({
52626
52685
  return baseGen3Config;
52627
52686
  } else if (cid === "146" && sysReg == sonicGen3Config.systemRegistry.toLowerCase()) {
52628
52687
  return sonicGen3Config;
52688
+ } else if (cid === "42161" && sysReg == arbGen3Config.systemRegistry.toLowerCase()) {
52689
+ return arbGen3Config;
52690
+ } else if (cid === "9745" && sysReg == plasmaGen3Config.systemRegistry.toLowerCase()) {
52691
+ return plasmaGen3Config;
52629
52692
  }
52630
52693
  throw new Error(`Chain ${chainId} and System Registry ${systemRegistry} not supported`);
52631
52694
  }
@@ -52691,7 +52754,7 @@ var require_bn = __commonJS({
52691
52754
  ctor.prototype = new TempCtor();
52692
52755
  ctor.prototype.constructor = ctor;
52693
52756
  }
52694
- function BN2(number, base3, endian) {
52757
+ function BN2(number, base2, endian) {
52695
52758
  if (BN2.isBN(number)) {
52696
52759
  return number;
52697
52760
  }
@@ -52700,11 +52763,11 @@ var require_bn = __commonJS({
52700
52763
  this.length = 0;
52701
52764
  this.red = null;
52702
52765
  if (number !== null) {
52703
- if (base3 === "le" || base3 === "be") {
52704
- endian = base3;
52705
- base3 = 10;
52766
+ if (base2 === "le" || base2 === "be") {
52767
+ endian = base2;
52768
+ base2 = 10;
52706
52769
  }
52707
- this._init(number || 0, base3 || 10, endian || "be");
52770
+ this._init(number || 0, base2 || 10, endian || "be");
52708
52771
  }
52709
52772
  }
52710
52773
  if (typeof module3 === "object") {
@@ -52739,17 +52802,17 @@ var require_bn = __commonJS({
52739
52802
  return left;
52740
52803
  return right;
52741
52804
  };
52742
- BN2.prototype._init = function init(number, base3, endian) {
52805
+ BN2.prototype._init = function init(number, base2, endian) {
52743
52806
  if (typeof number === "number") {
52744
- return this._initNumber(number, base3, endian);
52807
+ return this._initNumber(number, base2, endian);
52745
52808
  }
52746
52809
  if (typeof number === "object") {
52747
- return this._initArray(number, base3, endian);
52810
+ return this._initArray(number, base2, endian);
52748
52811
  }
52749
- if (base3 === "hex") {
52750
- base3 = 16;
52812
+ if (base2 === "hex") {
52813
+ base2 = 16;
52751
52814
  }
52752
- assert(base3 === (base3 | 0) && base3 >= 2 && base3 <= 36);
52815
+ assert(base2 === (base2 | 0) && base2 >= 2 && base2 <= 36);
52753
52816
  number = number.toString().replace(/\s+/g, "");
52754
52817
  var start = 0;
52755
52818
  if (number[0] === "-") {
@@ -52757,17 +52820,17 @@ var require_bn = __commonJS({
52757
52820
  this.negative = 1;
52758
52821
  }
52759
52822
  if (start < number.length) {
52760
- if (base3 === 16) {
52823
+ if (base2 === 16) {
52761
52824
  this._parseHex(number, start, endian);
52762
52825
  } else {
52763
- this._parseBase(number, base3, start);
52826
+ this._parseBase(number, base2, start);
52764
52827
  if (endian === "le") {
52765
- this._initArray(this.toArray(), base3, endian);
52828
+ this._initArray(this.toArray(), base2, endian);
52766
52829
  }
52767
52830
  }
52768
52831
  }
52769
52832
  };
52770
- BN2.prototype._initNumber = function _initNumber(number, base3, endian) {
52833
+ BN2.prototype._initNumber = function _initNumber(number, base2, endian) {
52771
52834
  if (number < 0) {
52772
52835
  this.negative = 1;
52773
52836
  number = -number;
@@ -52792,9 +52855,9 @@ var require_bn = __commonJS({
52792
52855
  }
52793
52856
  if (endian !== "le")
52794
52857
  return;
52795
- this._initArray(this.toArray(), base3, endian);
52858
+ this._initArray(this.toArray(), base2, endian);
52796
52859
  };
52797
- BN2.prototype._initArray = function _initArray(number, base3, endian) {
52860
+ BN2.prototype._initArray = function _initArray(number, base2, endian) {
52798
52861
  assert(typeof number.length === "number");
52799
52862
  if (number.length <= 0) {
52800
52863
  this.words = [0];
@@ -52908,20 +52971,20 @@ var require_bn = __commonJS({
52908
52971
  }
52909
52972
  return r;
52910
52973
  }
52911
- BN2.prototype._parseBase = function _parseBase(number, base3, start) {
52974
+ BN2.prototype._parseBase = function _parseBase(number, base2, start) {
52912
52975
  this.words = [0];
52913
52976
  this.length = 1;
52914
- for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base3) {
52977
+ for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base2) {
52915
52978
  limbLen++;
52916
52979
  }
52917
52980
  limbLen--;
52918
- limbPow = limbPow / base3 | 0;
52981
+ limbPow = limbPow / base2 | 0;
52919
52982
  var total = number.length - start;
52920
52983
  var mod = total % limbLen;
52921
52984
  var end = Math.min(total, total - mod) + start;
52922
52985
  var word = 0;
52923
52986
  for (var i = start; i < end; i += limbLen) {
52924
- word = parseBase(number, i, i + limbLen, base3);
52987
+ word = parseBase(number, i, i + limbLen, base2);
52925
52988
  this.imuln(limbPow);
52926
52989
  if (this.words[0] + word < 67108864) {
52927
52990
  this.words[0] += word;
@@ -52931,9 +52994,9 @@ var require_bn = __commonJS({
52931
52994
  }
52932
52995
  if (mod !== 0) {
52933
52996
  var pow = 1;
52934
- word = parseBase(number, i, number.length, base3);
52997
+ word = parseBase(number, i, number.length, base2);
52935
52998
  for (i = 0; i < mod; i++) {
52936
- pow *= base3;
52999
+ pow *= base2;
52937
53000
  }
52938
53001
  this.imuln(pow);
52939
53002
  if (this.words[0] + word < 67108864) {
@@ -53103,11 +53166,11 @@ var require_bn = __commonJS({
53103
53166
  52521875,
53104
53167
  60466176
53105
53168
  ];
53106
- BN2.prototype.toString = function toString(base3, padding) {
53107
- base3 = base3 || 10;
53169
+ BN2.prototype.toString = function toString(base2, padding) {
53170
+ base2 = base2 || 10;
53108
53171
  padding = padding | 0 || 1;
53109
53172
  var out;
53110
- if (base3 === 16 || base3 === "hex") {
53173
+ if (base2 === 16 || base2 === "hex") {
53111
53174
  out = "";
53112
53175
  var off = 0;
53113
53176
  var carry = 0;
@@ -53137,14 +53200,14 @@ var require_bn = __commonJS({
53137
53200
  }
53138
53201
  return out;
53139
53202
  }
53140
- if (base3 === (base3 | 0) && base3 >= 2 && base3 <= 36) {
53141
- var groupSize = groupSizes[base3];
53142
- var groupBase = groupBases[base3];
53203
+ if (base2 === (base2 | 0) && base2 >= 2 && base2 <= 36) {
53204
+ var groupSize = groupSizes[base2];
53205
+ var groupBase = groupBases[base2];
53143
53206
  out = "";
53144
53207
  var c = this.clone();
53145
53208
  c.negative = 0;
53146
53209
  while (!c.isZero()) {
53147
- var r = c.modrn(groupBase).toString(base3);
53210
+ var r = c.modrn(groupBase).toString(base2);
53148
53211
  c = c.idivn(groupBase);
53149
53212
  if (!c.isZero()) {
53150
53213
  out = zeros[groupSize - r.length] + r + out;
@@ -55615,7 +55678,7 @@ var require_bn = __commonJS({
55615
55678
  var require_src2 = __commonJS({
55616
55679
  "../../node_modules/@layerzerolabs/lz-v2-utilities/node_modules/base-x/src/index.js"(exports, module2) {
55617
55680
  "use strict";
55618
- function base3(ALPHABET) {
55681
+ function base2(ALPHABET) {
55619
55682
  if (ALPHABET.length >= 255) {
55620
55683
  throw new TypeError("Alphabet too long");
55621
55684
  }
@@ -55743,7 +55806,7 @@ var require_src2 = __commonJS({
55743
55806
  decode
55744
55807
  };
55745
55808
  }
55746
- module2.exports = base3;
55809
+ module2.exports = base2;
55747
55810
  }
55748
55811
  });
55749
55812
 
@@ -55763,6 +55826,7 @@ __export(queries_exports, {
55763
55826
  BASE_ASSETS: () => BASE_ASSETS,
55764
55827
  BATCH_SIZE: () => BATCH_SIZE,
55765
55828
  ETH_BASE_ASSETS: () => ETH_BASE_ASSETS,
55829
+ EUR_BASE_ASSETS: () => EUR_BASE_ASSETS,
55766
55830
  MessageStatus: () => MessageStatus,
55767
55831
  PRICED_TOKENS: () => PRICED_TOKENS,
55768
55832
  USD_BASE_ASSETS: () => USD_BASE_ASSETS,
@@ -55817,6 +55881,7 @@ __export(queries_exports, {
55817
55881
  getPoolsAndDestinations: () => getPoolsAndDestinations,
55818
55882
  getProtocolStats: () => getProtocolStats,
55819
55883
  getRebalanceStats: () => getRebalanceStats,
55884
+ getRebalanceValueUsd: () => getRebalanceValueUsd,
55820
55885
  getRewardsPayloadV1: () => getRewardsPayloadV1,
55821
55886
  getSToke: () => getSToke,
55822
55887
  getSTokeChainsForEnv: () => getSTokeChainsForEnv,
@@ -56201,18 +56266,20 @@ function getSTokeChainsForEnv({
56201
56266
 
56202
56267
  // utils/getAutopoolCategory.ts
56203
56268
  var ETH_BASE_ASSETS = ["ETH", "WETH"];
56204
- var USD_BASE_ASSETS = ["USDC", "DOLA"];
56269
+ var USD_BASE_ASSETS = ["USDC", "DOLA", "USDT0"];
56270
+ var EUR_BASE_ASSETS = ["EURC"];
56205
56271
  var AutopoolCategory = /* @__PURE__ */ ((AutopoolCategory2) => {
56206
56272
  AutopoolCategory2["ETH"] = "eth";
56207
- AutopoolCategory2["USD"] = "usd";
56208
56273
  AutopoolCategory2["CRYPTO"] = "crypto";
56274
+ AutopoolCategory2["STABLES"] = "stables";
56275
+ AutopoolCategory2["USD"] = "usd";
56209
56276
  return AutopoolCategory2;
56210
56277
  })(AutopoolCategory || {});
56211
56278
  var getAutopoolCategory = (baseAsset) => {
56212
- if (ETH_BASE_ASSETS.includes(baseAsset.toUpperCase())) {
56279
+ if (ETH_BASE_ASSETS.includes(baseAsset?.toUpperCase())) {
56213
56280
  return "eth" /* ETH */;
56214
- } else if (USD_BASE_ASSETS.includes(baseAsset.toUpperCase())) {
56215
- return "usd" /* USD */;
56281
+ } else if (USD_BASE_ASSETS.includes(baseAsset?.toUpperCase()) || EUR_BASE_ASSETS.includes(baseAsset?.toUpperCase())) {
56282
+ return "stables" /* STABLES */;
56216
56283
  }
56217
56284
  return "crypto" /* CRYPTO */;
56218
56285
  };
@@ -56319,8 +56386,43 @@ async function paginateQuery(queryFn, arrayKey, options = {}) {
56319
56386
  return results;
56320
56387
  }
56321
56388
 
56389
+ // functions/getPoolsAndDestinationsBackup.ts
56390
+ var import_utils2 = require("@tokemak/utils");
56391
+
56392
+ // functions/getBlobData.ts
56393
+ var getBlobData = async (blobName) => {
56394
+ try {
56395
+ const blobUrl = `https://kg4e5p7eknl8rdgg.public.blob.vercel-storage.com/${blobName}`;
56396
+ const response = await fetch(blobUrl, { cache: "no-store" });
56397
+ if (!response.ok) {
56398
+ console.warn(
56399
+ `Failed to fetch blob data for ${blobName}: ${response.status} ${response.statusText}`
56400
+ );
56401
+ return null;
56402
+ }
56403
+ const data = await response.text();
56404
+ return JSON.parse(data);
56405
+ } catch (error) {
56406
+ console.warn(`Failed to fetch blob data for ${blobName}:`, error);
56407
+ return null;
56408
+ }
56409
+ };
56410
+
56411
+ // functions/getPoolsAndDestinationsBackup.ts
56412
+ var getPoolsAndDestinationsBackup = async (chainId) => {
56413
+ try {
56414
+ const networkName = (0, import_utils2.getNetwork)(chainId)?.name.toLowerCase();
56415
+ const backupData = await getBlobData(
56416
+ `${networkName}-getPoolsAndDestinations-latest-success.json`
56417
+ );
56418
+ return backupData?.data;
56419
+ } catch (e) {
56420
+ console.error(e);
56421
+ }
56422
+ };
56423
+
56322
56424
  // functions/getChainAutopools.ts
56323
- var import_utils4 = require("@tokemak/utils");
56425
+ var import_utils6 = require("@tokemak/utils");
56324
56426
  var import_viem2 = require("viem");
56325
56427
 
56326
56428
  // constants/tokenOrders.ts
@@ -56418,10 +56520,31 @@ var getPoolsAndDestinations = async (wagmiConfig, { chainId }) => {
56418
56520
  );
56419
56521
  return autopoolsAndDestinations;
56420
56522
  } catch (error) {
56421
- console.error(`Error on ${chainId} in getPoolsAndDestionations:`, error);
56523
+ console.error(`Error on ${chainId} in getPoolsAndDestinations:`, error);
56422
56524
  }
56423
56525
  };
56424
56526
 
56527
+ // functions/getBackupApr.ts
56528
+ var import_utils4 = require("@tokemak/utils");
56529
+ var getBackupApr = async (chainId, poolAddress) => {
56530
+ try {
56531
+ const networkName = (0, import_utils4.getNetwork)(chainId)?.name.toLowerCase();
56532
+ const backupData = await getBlobData(
56533
+ `${networkName}-getChainAutopools-latest-success.json`
56534
+ );
56535
+ if (backupData) {
56536
+ const backupApr = backupData.data.find(
56537
+ (item) => item.poolAddress.toLowerCase() === poolAddress.toLowerCase()
56538
+ )?.apr.base;
56539
+ return backupApr || 0;
56540
+ }
56541
+ } catch (e) {
56542
+ console.error(e);
56543
+ return 0;
56544
+ }
56545
+ return null;
56546
+ };
56547
+
56425
56548
  // functions/getChainAutopools.ts
56426
56549
  var getChainAutopools = async (wagmiConfig, {
56427
56550
  chainId,
@@ -56435,14 +56558,16 @@ var getChainAutopools = async (wagmiConfig, {
56435
56558
  const genStratAprs = await getGenStratAprs({
56436
56559
  chainId
56437
56560
  });
56438
- const autopoolsAndDestinations = await getPoolsAndDestinations(
56439
- wagmiConfig,
56440
- {
56441
- chainId
56442
- }
56443
- );
56561
+ let autopoolsAndDestinations = await getPoolsAndDestinations(wagmiConfig, {
56562
+ chainId
56563
+ });
56444
56564
  if (!autopoolsAndDestinations) {
56445
- throw new Error(`No autopools and destinations found for ${chainId}`);
56565
+ const backupData = await getPoolsAndDestinationsBackup(chainId);
56566
+ if (backupData) {
56567
+ autopoolsAndDestinations = backupData;
56568
+ } else {
56569
+ throw new Error(`No autopools and destinations found for ${chainId}`);
56570
+ }
56446
56571
  }
56447
56572
  const vaultAddedMapping = vaultAddeds.reduce((acc, vaultAdded) => {
56448
56573
  acc[vaultAdded.vault.toLowerCase()] = Number(vaultAdded.blockTimestamp);
@@ -56450,8 +56575,14 @@ var getChainAutopools = async (wagmiConfig, {
56450
56575
  }, {});
56451
56576
  const autopools = await Promise.all(
56452
56577
  autopoolsAndDestinations.map(async (autopool) => {
56453
- const baseAsset = (0, import_utils4.getToken)(autopool.baseAsset);
56454
- let baseAssetPrice = prices[baseAsset.symbol.toUpperCase()];
56578
+ let baseAsset = (0, import_utils6.getToken)(autopool.baseAsset);
56579
+ if (!baseAsset?.symbol) {
56580
+ console.error(
56581
+ "FIX THIS BEFORE PROD: base asset not found",
56582
+ autopool.baseAsset
56583
+ );
56584
+ }
56585
+ let baseAssetPrice = prices[(baseAsset?.symbol || "").toUpperCase()];
56455
56586
  if (!baseAssetPrice) {
56456
56587
  baseAssetPrice = await getTokenPrice({
56457
56588
  chainId: baseAsset.chainId,
@@ -56459,18 +56590,18 @@ var getChainAutopools = async (wagmiConfig, {
56459
56590
  }) || 0;
56460
56591
  }
56461
56592
  const timestamp = vaultAddedMapping[autopool.poolAddress.toLowerCase()];
56462
- const totalAssets = (0, import_utils4.formatUnitsNum)(
56593
+ const totalAssets = (0, import_utils6.formatUnitsNum)(
56463
56594
  autopool.totalAssets,
56464
56595
  baseAsset.decimals
56465
56596
  );
56466
56597
  const tvl = totalAssets * baseAssetPrice;
56467
- const totalIdleAssets = (0, import_utils4.formatUnitsNum)(
56598
+ const totalIdleAssets = (0, import_utils6.formatUnitsNum)(
56468
56599
  autopool.totalIdle,
56469
56600
  baseAsset.decimals
56470
56601
  );
56471
56602
  const exchangeValues = {};
56472
56603
  const destinations = autopool.destinations.map((destination) => {
56473
- const debtValueHeldByVaultEth = (0, import_utils4.formatUnitsNum)(
56604
+ const debtValueHeldByVaultEth = (0, import_utils6.formatUnitsNum)(
56474
56605
  destination.debtValueHeldByVault,
56475
56606
  baseAsset.decimals
56476
56607
  );
@@ -56483,8 +56614,8 @@ var getChainAutopools = async (wagmiConfig, {
56483
56614
  destination.underlyingTokenValueHeld
56484
56615
  );
56485
56616
  let underlyingTokens = tokensWithValue.map((token) => {
56486
- const tokenDetails = (0, import_utils4.getToken)(token.tokenAddress);
56487
- let value = (0, import_utils4.formatUnitsNum)(
56617
+ const tokenDetails = (0, import_utils6.getToken)(token.tokenAddress);
56618
+ let value = (0, import_utils6.formatUnitsNum)(
56488
56619
  token.valueHeldInEth,
56489
56620
  baseAsset.decimals
56490
56621
  );
@@ -56500,7 +56631,7 @@ var getChainAutopools = async (wagmiConfig, {
56500
56631
  if (underlyingTokenAddress) {
56501
56632
  underlyingTokens = [
56502
56633
  {
56503
- ...(0, import_utils4.getToken)(underlyingTokenAddress, chainId),
56634
+ ...(0, import_utils6.getToken)(underlyingTokenAddress, chainId),
56504
56635
  valueUsd: debtValueHeldByVaultEth * baseAssetPrice,
56505
56636
  value: debtValueHeldByVaultEth
56506
56637
  }
@@ -56512,16 +56643,16 @@ var getChainAutopools = async (wagmiConfig, {
56512
56643
  ...destination,
56513
56644
  debtValueHeldByVaultUsd: debtValueHeldByVaultEth * baseAssetPrice,
56514
56645
  debtValueHeldByVaultEth,
56515
- compositeReturn: isGenStrat ? genStratAprs?.[autopool.poolAddress]?.[destination.vaultAddress]?.apr || 0 : (0, import_utils4.formatUnitsNum)(destination.compositeReturn, 4),
56646
+ compositeReturn: isGenStrat ? genStratAprs?.[autopool.poolAddress]?.[destination.vaultAddress]?.apr || 0 : (0, import_utils6.formatEtherNum)(destination.compositeReturn),
56516
56647
  debtValueHeldByVaultAllocation: debtValueHeldByVaultEth / totalAssets,
56517
56648
  underlyingTokens,
56518
- poolName: (0, import_utils4.formatPoolName)(destination.lpTokenName),
56519
- exchange: (0, import_utils4.getProtocol)(destination.exchangeName)
56649
+ poolName: (0, import_utils6.formatPoolName)(destination.lpTokenName),
56650
+ exchange: (0, import_utils6.getProtocol)(destination.exchangeName)
56520
56651
  };
56521
56652
  });
56522
56653
  const uniqueExchanges = Array.from(
56523
56654
  new Set(
56524
- destinations.map((d) => (0, import_utils4.getProtocol)(d.exchangeName)).filter(Boolean)
56655
+ destinations.map((d) => (0, import_utils6.getProtocol)(d.exchangeName)).filter(Boolean)
56525
56656
  )
56526
56657
  );
56527
56658
  const uniqueExchangesWithValueHeld = uniqueExchanges.map((exchange) => {
@@ -56580,12 +56711,15 @@ var getChainAutopools = async (wagmiConfig, {
56580
56711
  }
56581
56712
  );
56582
56713
  let UIBaseAsset = baseAsset;
56583
- if (baseAsset.symbol.toLowerCase() === import_tokenlist3.WETH_TOKEN.symbol.toLowerCase()) {
56714
+ if (baseAsset.symbol?.toLowerCase() === import_tokenlist3.WETH_TOKEN.symbol.toLowerCase()) {
56584
56715
  UIBaseAsset = import_tokenlist3.ETH_TOKEN;
56585
56716
  }
56586
- if (baseAsset.symbol.toLowerCase() === import_tokenlist3.WS_TOKEN.symbol.toLowerCase()) {
56717
+ if (baseAsset.symbol?.toLowerCase() === import_tokenlist3.WS_TOKEN.symbol.toLowerCase()) {
56587
56718
  UIBaseAsset = import_tokenlist3.S_TOKEN;
56588
56719
  }
56720
+ if (baseAsset.symbol?.toLowerCase() === import_tokenlist3.WXPL_TOKEN.symbol.toLowerCase()) {
56721
+ UIBaseAsset = import_tokenlist3.XPL_TOKEN;
56722
+ }
56589
56723
  const isNew = (Date.now() / 1e3 - timestamp) / 60 / 60 / 24 < 45;
56590
56724
  const aprs = autopoolsApr.find(
56591
56725
  (autopoolApr) => (0, import_viem2.getAddress)(autopoolApr.id) === (0, import_viem2.getAddress)(autopool.poolAddress)
@@ -56593,10 +56727,10 @@ var getChainAutopools = async (wagmiConfig, {
56593
56727
  let baseApr = aprs?.currentApy;
56594
56728
  let boostedApr = 0;
56595
56729
  let extraApr = 0;
56596
- const formattedRewarder7DayMAApy = (0, import_utils4.formatEtherNum)(
56730
+ const formattedRewarder7DayMAApy = (0, import_utils6.formatEtherNum)(
56597
56731
  BigInt(Number(aprs?.rewarder?.day7MAApy) || 0)
56598
56732
  );
56599
- const formattedRewarder30DayMAApy = (0, import_utils4.formatEtherNum)(
56733
+ const formattedRewarder30DayMAApy = (0, import_utils6.formatEtherNum)(
56600
56734
  BigInt(Number(aprs?.rewarder?.day30MAApy) || 0)
56601
56735
  );
56602
56736
  if (formattedRewarder7DayMAApy > 0) {
@@ -56618,16 +56752,34 @@ var getChainAutopools = async (wagmiConfig, {
56618
56752
  if (!baseApr) {
56619
56753
  baseApr = 0;
56620
56754
  }
56755
+ if (baseApr === 0) {
56756
+ try {
56757
+ const backupApr = await getBackupApr(chainId, autopool.poolAddress);
56758
+ if (backupApr) {
56759
+ baseApr = backupApr;
56760
+ console.log("using backup apr", backupApr);
56761
+ }
56762
+ } catch (e) {
56763
+ console.error(e);
56764
+ console.log("unable to retrieve backup apr");
56765
+ }
56766
+ }
56767
+ if (baseApr === 0 && autopool.symbol.toLowerCase() === "baseusd") {
56768
+ baseApr = 0.0914;
56769
+ }
56621
56770
  let extraRewards = [];
56622
56771
  if (aprs?.rewarder?.extraRewarders?.length && aprs?.rewarder?.extraRewarders?.length > 0) {
56623
56772
  extraRewards = aprs?.rewarder?.extraRewarders.map((reward) => {
56624
- const token = (0, import_utils4.getToken)(reward?.rewardToken?.id, chainId);
56773
+ const token = (0, import_utils6.getToken)(reward?.rewardToken?.id, chainId);
56625
56774
  return {
56626
56775
  ...token,
56627
- apr: (0, import_utils4.formatEtherNum)(BigInt(reward.currentApy || 0))
56776
+ apr: (0, import_utils6.formatEtherNum)(BigInt(reward.currentApy || 0))
56628
56777
  };
56629
56778
  });
56630
56779
  }
56780
+ if (autopool?.symbol?.toLowerCase() === "plasmausd") {
56781
+ boostedApr = 0;
56782
+ }
56631
56783
  extraApr = extraRewards.reduce((acc, reward) => acc + reward.apr, 0);
56632
56784
  const combinedApr = baseApr + boostedApr + extraApr;
56633
56785
  let denominatedToken = import_tokenlist3.ETH_TOKEN;
@@ -56636,13 +56788,13 @@ var getChainAutopools = async (wagmiConfig, {
56636
56788
  if (denominatedIn?.symbol?.toLowerCase() === "weth") {
56637
56789
  denominatedToken = import_tokenlist3.ETH_TOKEN;
56638
56790
  } else {
56639
- denominatedToken = (0, import_utils4.getToken)(denominatedIn?.id);
56791
+ denominatedToken = (0, import_utils6.getToken)(denominatedIn?.id);
56640
56792
  if (denominatedToken) {
56641
56793
  useDenominatedValues = true;
56642
56794
  }
56643
56795
  }
56644
56796
  let denominatedTokenPrice = 0;
56645
- const tokenSymbol = denominatedToken.symbol.toUpperCase();
56797
+ const tokenSymbol = denominatedToken.symbol?.toUpperCase();
56646
56798
  if (tokenSymbol in prices) {
56647
56799
  denominatedTokenPrice = prices[tokenSymbol];
56648
56800
  } else {
@@ -56651,12 +56803,12 @@ var getChainAutopools = async (wagmiConfig, {
56651
56803
  tokenAddress: denominatedToken.address
56652
56804
  }) || 0;
56653
56805
  }
56654
- const navPerShareBaseAsset = (0, import_utils4.formatUnitsNum)(
56806
+ const navPerShareBaseAsset = (0, import_utils6.formatUnitsNum)(
56655
56807
  autopool.navPerShare,
56656
56808
  baseAsset.decimals
56657
56809
  );
56658
56810
  const assets = convertBaseAssetToTokenPricesAndDenom(
56659
- (0, import_utils4.formatUnitsNum)(autopool.totalAssets, baseAsset.decimals),
56811
+ (0, import_utils6.formatUnitsNum)(autopool.totalAssets, baseAsset.decimals),
56660
56812
  baseAssetPrice,
56661
56813
  denominatedTokenPrice,
56662
56814
  prices
@@ -56763,7 +56915,7 @@ var getChainAutopools = async (wagmiConfig, {
56763
56915
  });
56764
56916
  const autopoolInfo = getAutopoolInfo(autopool.symbol);
56765
56917
  if (autopoolInfo && !autopoolInfo.description) {
56766
- autopoolInfo.description = `Autopool featuring ${UIBaseAsset.symbol} deployed across integrated DEXs and lending protocols on ${(0, import_utils4.getNetwork)(chainId)?.name}.`;
56918
+ autopoolInfo.description = `Autopool featuring ${UIBaseAsset.symbol} deployed across integrated DEXs and lending protocols on ${(0, import_utils6.getNetwork)(chainId)?.name}.`;
56767
56919
  }
56768
56920
  return {
56769
56921
  ...autopool,
@@ -56788,7 +56940,7 @@ var getChainAutopools = async (wagmiConfig, {
56788
56940
  UITokens,
56789
56941
  UIExchanges: finalUIExchanges,
56790
56942
  tokens: uniqueTokens,
56791
- chain: (0, import_utils4.getNetwork)(chainId),
56943
+ chain: (0, import_utils6.getNetwork)(chainId),
56792
56944
  apr: {
56793
56945
  base: baseApr,
56794
56946
  boosted: boostedApr,
@@ -56852,36 +57004,40 @@ var getAutopools = async (wagmiConfig, {
56852
57004
  };
56853
57005
 
56854
57006
  // functions/getAutopoolRebalances.ts
56855
- var import_clients = require("@tokemak/graph-cli/dist/clients");
56856
- var getAutopoolRebalances = async (id, chainId = 1) => {
56857
- const { GetAutopoolRebalances } = (0, import_clients.getSdkByChainId)(chainId);
56858
- const { autopoolRebalances } = await GetAutopoolRebalances({
56859
- address: id
57007
+ var import_graph_cli2 = require("@tokemak/graph-cli");
57008
+ var getAutopoolRebalances = async (id, chainId = 1, options) => {
57009
+ const { GetAutopoolRebalances } = (0, import_graph_cli2.getSdkByChainId)(chainId);
57010
+ const first = options?.first ?? 1e3;
57011
+ const maxPages = options?.maxPages ?? 100;
57012
+ const queryFn = ({ first: first2, skip }) => GetAutopoolRebalances({ address: id, first: first2, skip });
57013
+ const all = await paginateQuery(queryFn, "autopoolRebalances", {
57014
+ first,
57015
+ maxPages,
57016
+ onPage: options?.onPage
56860
57017
  });
56861
- const length = autopoolRebalances.length;
56862
- return autopoolRebalances.map((rebalance, index) => ({
57018
+ const length = all.length;
57019
+ return all.map((rebalance, index) => ({
56863
57020
  ...rebalance,
56864
57021
  ix: length - index
56865
57022
  }));
56866
57023
  };
56867
57024
 
56868
57025
  // functions/getAutopoolsRebalances.ts
56869
- var import_graph_cli2 = require("@tokemak/graph-cli");
57026
+ var import_graph_cli3 = require("@tokemak/graph-cli");
56870
57027
  var getAutopoolsRebalances = async (chainId = 1) => {
56871
- const { GetAutopoolsRebalances } = (0, import_graph_cli2.getSdkByChainId)(chainId);
57028
+ const { GetAutopoolsRebalances } = (0, import_graph_cli3.getSdkByChainId)(chainId);
56872
57029
  const { autopools } = await GetAutopoolsRebalances();
56873
57030
  const rebalances = autopools.map(({ rebalances: rebalances2 }) => rebalances2);
56874
57031
  return rebalances.flat().sort((a, b) => b.timestamp - a.timestamp);
56875
57032
  };
56876
57033
 
56877
57034
  // functions/getAutopoolsHistory.ts
56878
- var import_chains3 = require("viem/chains");
56879
57035
  var import_viem4 = require("viem");
56880
57036
 
56881
57037
  // functions/getAutopoolsDayData.ts
56882
- var import_graph_cli3 = require("@tokemak/graph-cli");
57038
+ var import_graph_cli4 = require("@tokemak/graph-cli");
56883
57039
  var getAutopoolsDayData = async (chainId, timestamp) => {
56884
- const { GetAutopoolsDayData } = (0, import_graph_cli3.getSdkByChainId)(chainId);
57040
+ const { GetAutopoolsDayData } = (0, import_graph_cli4.getSdkByChainId)(chainId);
56885
57041
  const PAGE_SIZE = 1e3;
56886
57042
  let allResults = [];
56887
57043
  let hasMore = true;
@@ -56892,7 +57048,16 @@ var getAutopoolsDayData = async (chainId, timestamp) => {
56892
57048
  first: PAGE_SIZE,
56893
57049
  skip
56894
57050
  });
56895
- allResults = [...allResults, ...autopoolDayDatas];
57051
+ const autopoolDayDatasWithVaultId = autopoolDayDatas.map(
57052
+ (autopoolDayData) => {
57053
+ const parsedVaultId = autopoolDayData.id.split("-")[0];
57054
+ return {
57055
+ ...autopoolDayData,
57056
+ vault: { id: parsedVaultId }
57057
+ };
57058
+ }
57059
+ );
57060
+ allResults = [...allResults, ...autopoolDayDatasWithVaultId];
56896
57061
  if (autopoolDayDatas.length < PAGE_SIZE) {
56897
57062
  hasMore = false;
56898
57063
  } else {
@@ -56909,23 +57074,13 @@ var getAutopoolsHistory = async (autopools, days, includeTestnet = false) => {
56909
57074
  throw new Error("No autopools found");
56910
57075
  }
56911
57076
  const timestampXDaysAgo = Math.floor(Date.now() / 1e3) - 60 * 60 * 24 * days;
56912
- const ethAutopoolDayDatas = await getAutopoolsDayData(
56913
- import_chains3.mainnet.id,
56914
- timestampXDaysAgo
56915
- );
56916
- const baseAutopoolDayDatas = await getAutopoolsDayData(
56917
- import_chains3.base.id,
56918
- timestampXDaysAgo
56919
- );
56920
- const sonicAutopoolDayDatas = await getAutopoolsDayData(
56921
- import_chains3.sonic.id,
56922
- timestampXDaysAgo
57077
+ const chains = getChainsForEnv({ includeTestnet });
57078
+ const autopoolDayDatas = await Promise.all(
57079
+ chains.map(
57080
+ (chain) => getAutopoolsDayData(chain.chainId, timestampXDaysAgo)
57081
+ )
56923
57082
  );
56924
- let groupedDayDatas = [
56925
- ...ethAutopoolDayDatas,
56926
- ...baseAutopoolDayDatas,
56927
- ...sonicAutopoolDayDatas
56928
- ];
57083
+ let groupedDayDatas = [...autopoolDayDatas.flat()];
56929
57084
  const groupedByVault = groupedDayDatas.reduce((acc, data) => {
56930
57085
  const vaultId = data.vault.id.toLowerCase();
56931
57086
  if (!acc[vaultId]) {
@@ -56997,7 +57152,7 @@ var import_abis2 = require("@tokemak/abis");
56997
57152
  var import_config4 = require("@tokemak/config");
56998
57153
  var import_core2 = require("@wagmi/core");
56999
57154
  var import_viem5 = require("viem");
57000
- var import_chains4 = require("viem/chains");
57155
+ var import_chains3 = require("viem/chains");
57001
57156
  var getSushiLP = async (wagmiConfig, { ethPrice }) => {
57002
57157
  const { sushiPool, lpRewardsV1Url } = (0, import_config4.getMainnetConfig)();
57003
57158
  const sushiPoolContract = {
@@ -57012,12 +57167,12 @@ var getSushiLP = async (wagmiConfig, { ethPrice }) => {
57012
57167
  {
57013
57168
  ...sushiPoolContract,
57014
57169
  functionName: "getReserves",
57015
- chainId: import_chains4.mainnet.id
57170
+ chainId: import_chains3.mainnet.id
57016
57171
  },
57017
57172
  {
57018
57173
  ...sushiPoolContract,
57019
57174
  functionName: "totalSupply",
57020
- chainId: import_chains4.mainnet.id
57175
+ chainId: import_chains3.mainnet.id
57021
57176
  }
57022
57177
  ]
57023
57178
  }
@@ -57047,9 +57202,9 @@ var getSushiLP = async (wagmiConfig, { ethPrice }) => {
57047
57202
  };
57048
57203
 
57049
57204
  // functions/getChainUserActivity.ts
57050
- var import_graph_cli4 = require("@tokemak/graph-cli");
57205
+ var import_graph_cli5 = require("@tokemak/graph-cli");
57051
57206
  var getChainUserActivity = async (address, chainId = 1) => {
57052
- const { GetUserBalanceChangeHistory } = (0, import_graph_cli4.getSdkByChainId)(chainId);
57207
+ const { GetUserBalanceChangeHistory } = (0, import_graph_cli5.getSdkByChainId)(chainId);
57053
57208
  try {
57054
57209
  const { userAutopoolBalanceChanges } = await GetUserBalanceChangeHistory({
57055
57210
  userAddress: address
@@ -57120,7 +57275,7 @@ var getRewardsPayloadV1 = async (cycleHash, account, rewardsV1Url) => {
57120
57275
  // functions/getUserAutoEthRewards.ts
57121
57276
  var import_abis3 = require("@tokemak/abis");
57122
57277
  var import_core3 = require("@wagmi/core");
57123
- var import_utils7 = require("@tokemak/utils");
57278
+ var import_utils10 = require("@tokemak/utils");
57124
57279
  var getAutoEthRewards = async (wagmiConfig, {
57125
57280
  account,
57126
57281
  currentCycleIndex,
@@ -57158,7 +57313,7 @@ var getAutoEthRewards = async (wagmiConfig, {
57158
57313
  const currentAmount = Number(drippingHashPayload?.summary?.currentAmount);
57159
57314
  const previousAmount = Number(drippingHashPayload?.summary?.previousAmount);
57160
57315
  const cycleDuration = 604800;
57161
- const lastCycleStart = (0, import_utils7.convertChainCycleToUnix)(Number(currentCycleIndex));
57316
+ const lastCycleStart = (0, import_utils10.convertChainCycleToUnix)(Number(currentCycleIndex));
57162
57317
  const timeSinceCycleStart = Date.now() / 1e3 - lastCycleStart;
57163
57318
  const currentUserRewards = currentAmount * Math.min(timeSinceCycleStart, cycleDuration) / cycleDuration + previousAmount;
57164
57319
  const lastWeekRewards = Number(lastWeekHashPayload?.summary?.currentAmount);
@@ -57179,7 +57334,7 @@ var getUserAutoEthRewards = async (wagmiConfig, rewardsV1Url, rewardsHash, addre
57179
57334
  rewardsHash,
57180
57335
  chainId
57181
57336
  });
57182
- const currentUserRewardsUsd = (0, import_utils7.formatCurrency)(
57337
+ const currentUserRewardsUsd = (0, import_utils10.formatCurrency)(
57183
57338
  ethPrice * (autoETHRewards?.currentUserRewards || 0)
57184
57339
  );
57185
57340
  return { ...autoETHRewards, currentUserRewardsUsd };
@@ -57240,7 +57395,7 @@ var getUserRewardsV1 = async (wagmiConfig, {
57240
57395
  var import_abis5 = require("@tokemak/abis");
57241
57396
  var import_core5 = require("@wagmi/core");
57242
57397
  var import_config5 = require("@tokemak/config");
57243
- var import_chains5 = require("viem/chains");
57398
+ var import_chains4 = require("viem/chains");
57244
57399
  var getUserV1 = async (wagmiConfig, {
57245
57400
  currentCycleIndex,
57246
57401
  address,
@@ -57255,14 +57410,14 @@ var getUserV1 = async (wagmiConfig, {
57255
57410
  autoEthGuardedRewards,
57256
57411
  rewardsV1,
57257
57412
  missedTokeRewards
57258
- } = (0, import_config5.getMainnetConfig)(import_chains5.mainnet.id);
57413
+ } = (0, import_config5.getMainnetConfig)(import_chains4.mainnet.id);
57259
57414
  try {
57260
57415
  const userStakedTokeV1 = await (0, import_core5.readContract)(wagmiConfig, {
57261
57416
  address: stakingV1,
57262
57417
  abi: import_abis5.stakingV1Abi,
57263
57418
  functionName: "availableForWithdrawal",
57264
57419
  args: [address, 0n],
57265
- chainId: import_chains5.mainnet.id
57420
+ chainId: import_chains4.mainnet.id
57266
57421
  });
57267
57422
  const tokeRewards = await getUserRewardsV1(wagmiConfig, {
57268
57423
  address,
@@ -57344,12 +57499,12 @@ var getUserV1 = async (wagmiConfig, {
57344
57499
  };
57345
57500
 
57346
57501
  // functions/getChainUserAutopoolsHistory.tsx
57347
- var import_graph_cli5 = require("@tokemak/graph-cli");
57502
+ var import_graph_cli6 = require("@tokemak/graph-cli");
57348
57503
  var getChainUserAutopoolsHistory = async ({
57349
57504
  address,
57350
57505
  chainId = 1
57351
57506
  }) => {
57352
- const { GetUserVaultsDayData } = (0, import_graph_cli5.getSdkByChainId)(chainId);
57507
+ const { GetUserVaultsDayData } = (0, import_graph_cli6.getSdkByChainId)(chainId);
57353
57508
  const oneYearAgoTimestamp = Math.floor(Date.now() / 1e3) - 365 * 24 * 60 * 60;
57354
57509
  try {
57355
57510
  if (address) {
@@ -57367,21 +57522,21 @@ var getChainUserAutopoolsHistory = async ({
57367
57522
  };
57368
57523
 
57369
57524
  // functions/getUserAutopoolsHistory.ts
57370
- var import_utils11 = require("@tokemak/utils");
57525
+ var import_utils14 = require("@tokemak/utils");
57371
57526
 
57372
57527
  // functions/getTokenValueDayDatas.ts
57373
- var import_chains6 = require("viem/chains");
57374
- var import_utils8 = require("@tokemak/utils");
57528
+ var import_chains5 = require("viem/chains");
57529
+ var import_utils11 = require("@tokemak/utils");
57375
57530
  var import_viem6 = require("viem");
57376
- var import_graph_cli6 = require("@tokemak/graph-cli");
57377
- var getTokenValueDayDatas = async (tokenAddress, chainId = import_chains6.mainnet.id) => {
57378
- const { GetTokenValueDayDatas } = (0, import_graph_cli6.getSdkByChainId)(chainId);
57531
+ var import_graph_cli7 = require("@tokemak/graph-cli");
57532
+ var getTokenValueDayDatas = async (tokenAddress, chainId = import_chains5.mainnet.id) => {
57533
+ const { GetTokenValueDayDatas } = (0, import_graph_cli7.getSdkByChainId)(chainId);
57379
57534
  try {
57380
57535
  const { tokenValueDayDatas } = await GetTokenValueDayDatas({
57381
57536
  tokenAddress: tokenAddress.toLowerCase()
57382
57537
  });
57383
57538
  const historicalPrice = tokenValueDayDatas.map((tokenValueDayData) => {
57384
- const date = (0, import_utils8.convertTimestampToDate)(
57539
+ const date = (0, import_utils11.convertTimestampToDate)(
57385
57540
  tokenValueDayData.lastSnapshotTimestamp
57386
57541
  );
57387
57542
  const usdPrice = (0, import_viem6.formatUnits)(tokenValueDayData.priceInUsd, 8);
@@ -57400,28 +57555,55 @@ var getTokenValueDayDatas = async (tokenAddress, chainId = import_chains6.mainne
57400
57555
  // functions/getTokenPrices.ts
57401
57556
  var import_tokenlist4 = require("@tokemak/tokenlist");
57402
57557
  var import_constants6 = require("@tokemak/constants");
57558
+
57559
+ // functions/getBackupTokenPrices.ts
57560
+ var getBackupTokenPrices = async () => {
57561
+ try {
57562
+ const backupData = await getBlobData(`getTokenPrices-latest-success.json`);
57563
+ if (backupData) {
57564
+ return backupData;
57565
+ }
57566
+ } catch (e) {
57567
+ console.error(e);
57568
+ return void 0;
57569
+ }
57570
+ return void 0;
57571
+ };
57572
+
57573
+ // functions/getTokenPrices.ts
57403
57574
  var BASE_ASSETS = [
57404
- { ...import_tokenlist4.ETH_TOKEN, symbol: "ETH" },
57405
- { ...import_tokenlist4.PXETH_TOKEN, symbol: "PXETH" },
57406
- { ...import_tokenlist4.USDC_TOKEN, symbol: "USDC" },
57407
- { ...import_tokenlist4.DOLA_TOKEN, symbol: "DOLA" },
57408
- { ...import_tokenlist4.S_TOKEN, symbol: "S" }
57575
+ { ...import_tokenlist4.ETH_TOKEN, symbol: "ETH", coinGeckoId: "ethereum" },
57576
+ { ...import_tokenlist4.PXETH_TOKEN, symbol: "PXETH", coinGeckoId: "dinero-staked-eth" },
57577
+ { ...import_tokenlist4.USDC_TOKEN, symbol: "USDC", coinGeckoId: "usd-coin" },
57578
+ { ...import_tokenlist4.DOLA_TOKEN, symbol: "DOLA", coinGeckoId: "dola-usd" },
57579
+ { ...import_tokenlist4.S_TOKEN, symbol: "S" },
57580
+ { ...import_tokenlist4.EURC_TOKEN, symbol: "EURC", coinGeckoId: "euro-coin" },
57581
+ { ...import_tokenlist4.USDT_TOKEN, symbol: "USDT", coinGeckoId: "tether" },
57582
+ { ...import_tokenlist4.USDT0_TOKEN, symbol: "USDT0", coinGeckoId: "tether" }
57409
57583
  ];
57410
57584
  var PRICED_TOKENS = [
57411
57585
  ...BASE_ASSETS,
57412
- { ...import_tokenlist4.TOKE_TOKEN, symbol: "TOKE" }
57586
+ { ...import_tokenlist4.TOKE_TOKEN, symbol: "TOKE" },
57587
+ { ...import_tokenlist4.SILO_TOKEN, symbol: "SILO" },
57588
+ { ...import_tokenlist4.XPL_TOKEN, address: import_tokenlist4.WXPL_TOKEN.address, symbol: "XPL" },
57589
+ { ...import_tokenlist4.USDT0_TOKEN, symbol: "USDT0" }
57413
57590
  ];
57414
57591
  var WRAPPED_TOKENS = [
57415
57592
  { ...import_tokenlist4.WETH_TOKEN, symbol: "WETH" },
57416
- { ...import_tokenlist4.WS_TOKEN, symbol: "WS" }
57593
+ { ...import_tokenlist4.WS_TOKEN, symbol: "WS" },
57594
+ { ...import_tokenlist4.WXPL_TOKEN, symbol: "WXPL" }
57417
57595
  ];
57418
- var getTokenPrices = async () => {
57596
+ var isStale = (timestamp) => {
57597
+ return timestamp - Math.floor(Date.now() / 1e3) > 5 * 60;
57598
+ };
57599
+ var getTokenPrices = async (isCronJob = false) => {
57419
57600
  try {
57420
57601
  const body = {
57421
- tokens: PRICED_TOKENS.map((asset, index) => ({
57602
+ tokens: PRICED_TOKENS.map((asset) => ({
57422
57603
  token: asset.address,
57423
57604
  chainId: asset.chainId,
57424
- systemName: "gen3"
57605
+ systemName: "gen3",
57606
+ timeoutMS: 5 * 1e3
57425
57607
  }))
57426
57608
  };
57427
57609
  const response = await fetch(`${import_constants6.TOKEMAK_PRICES_STAGING_URL}`, {
@@ -57436,43 +57618,73 @@ var getTokenPrices = async () => {
57436
57618
  const priceData = data.find(
57437
57619
  (item) => item.token.toLowerCase() === asset.address.toLowerCase() && item.chainId === asset.chainId
57438
57620
  );
57439
- acc[asset.symbol] = priceData?.price || 0;
57621
+ acc[asset.symbol] = priceData?.price ?? 0;
57440
57622
  return acc;
57441
57623
  }, {});
57442
- return { ...prices, WETH: prices.ETH, WS: prices.S };
57624
+ const timestamp = Math.floor(Date.now() / 1e3);
57625
+ return {
57626
+ timestamp,
57627
+ isStale: false,
57628
+ prices: {
57629
+ ...prices,
57630
+ WETH: prices.ETH,
57631
+ WS: prices.S,
57632
+ WXPL: prices.XPL
57633
+ }
57634
+ };
57443
57635
  } catch (e) {
57444
- console.log("pricing failed, falling back to getTokenPrice");
57445
- console.error(e);
57446
- const pricesResponse = await Promise.all(
57447
- PRICED_TOKENS.map(
57448
- (asset) => getTokenPrice({ tokenAddress: asset.address, chainId: asset.chainId })
57449
- )
57450
- );
57451
- const prices = pricesResponse.reduce((acc, price, index) => {
57452
- acc[PRICED_TOKENS[index].symbol] = price || 0;
57453
- return acc;
57454
- }, {});
57455
- return { ...prices, WETH: prices.ETH, WS: prices.S };
57636
+ if (isCronJob) {
57637
+ return {
57638
+ prices: void 0,
57639
+ timestamp: void 0,
57640
+ isStale: false
57641
+ };
57642
+ } else {
57643
+ const backupPrices = await getBackupTokenPrices();
57644
+ if (backupPrices) {
57645
+ return {
57646
+ prices: backupPrices.prices,
57647
+ timestamp: backupPrices.timestamp,
57648
+ isStale: isStale(backupPrices.timestamp)
57649
+ };
57650
+ }
57651
+ return {
57652
+ prices: void 0,
57653
+ timestamp: void 0,
57654
+ isStale: false
57655
+ };
57656
+ }
57456
57657
  }
57457
57658
  };
57458
57659
 
57459
57660
  // functions/getHistoricalTokenPrices.ts
57460
57661
  var import_tokenlist5 = require("@tokemak/tokenlist");
57662
+ var hasCoinGeckoId = (asset) => typeof asset?.coinGeckoId === "string" && asset.coinGeckoId.length > 0;
57663
+ var getBlobHistoricalTokenPrices = async (tokenSymbol) => {
57664
+ const blobName = `historical_v2/${tokenSymbol}-latest-success.json`;
57665
+ const res = await getBlobData(blobName);
57666
+ if (!res?.data || !Array.isArray(res.data))
57667
+ return [];
57668
+ return res.data.map(({ timestamp, date, price }) => ({
57669
+ timestamp,
57670
+ date,
57671
+ price
57672
+ }));
57673
+ };
57461
57674
  var getHistoricalTokenPrices = async () => {
57462
57675
  const ETH_ADDRESS_IN_SUBGRAPH = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
57463
57676
  const historicalBaseAssetPrices = await Promise.all(
57464
57677
  BASE_ASSETS.map(async (baseAsset) => {
57465
- let address = baseAsset.address;
57466
- if (baseAsset.address === import_tokenlist5.ETH_TOKEN.address) {
57467
- address = ETH_ADDRESS_IN_SUBGRAPH;
57468
- }
57469
- return {
57470
- ...baseAsset,
57471
- prices: await getTokenValueDayDatas(
57678
+ if (!hasCoinGeckoId(baseAsset)) {
57679
+ const address = baseAsset.address === import_tokenlist5.ETH_TOKEN.address ? ETH_ADDRESS_IN_SUBGRAPH : baseAsset.address;
57680
+ const prices2 = await getTokenValueDayDatas(
57472
57681
  address,
57473
57682
  baseAsset.chainId
57474
- )
57475
- };
57683
+ );
57684
+ return { ...baseAsset, prices: prices2 ?? [] };
57685
+ }
57686
+ const prices = await getBlobHistoricalTokenPrices(baseAsset.symbol);
57687
+ return { ...baseAsset, prices };
57476
57688
  })
57477
57689
  );
57478
57690
  const allTimestamps = /* @__PURE__ */ new Set();
@@ -57491,51 +57703,32 @@ var getHistoricalTokenPrices = async () => {
57491
57703
  ...BASE_ASSETS.map((asset) => asset.symbol),
57492
57704
  "USD"
57493
57705
  ];
57706
+ const usdPrices = /* @__PURE__ */ new Map();
57707
+ baseAssetsWithUsd.forEach((asset) => {
57708
+ if (asset !== "USD") {
57709
+ const assetData = historicalBaseAssetPrices.find(
57710
+ (a) => a.symbol === asset
57711
+ );
57712
+ const priceData = findClosestTimestampEntry(
57713
+ assetData?.prices || [],
57714
+ timestamp
57715
+ );
57716
+ usdPrices.set(asset, priceData ? parseFloat(priceData.price) : 0);
57717
+ }
57718
+ });
57494
57719
  baseAssetsWithUsd.forEach((asset1) => {
57495
57720
  prices[asset1] = {};
57496
57721
  baseAssetsWithUsd.forEach((asset2) => {
57497
57722
  if (asset1 === asset2) {
57498
57723
  prices[asset1][asset2] = 1;
57499
- } else if (asset1 === "USD" && asset2 !== "USD") {
57500
- const asset2Data = historicalBaseAssetPrices.find(
57501
- (a) => a.symbol === asset2
57502
- );
57503
- const priceData = findClosestTimestampEntry(
57504
- asset2Data?.prices || [],
57505
- timestamp
57506
- );
57507
- prices[asset1][asset2] = priceData ? parseFloat(priceData.price) : 0;
57508
- } else if (asset2 === "USD" && asset1 !== "USD") {
57509
- const asset1Data = historicalBaseAssetPrices.find(
57510
- (a) => a.symbol === asset1
57511
- );
57512
- const priceData = findClosestTimestampEntry(
57513
- asset1Data?.prices || [],
57514
- timestamp
57515
- );
57516
- prices[asset1][asset2] = priceData ? parseFloat(priceData.price) : 0;
57517
- } else if (asset1 !== "USD" && asset2 !== "USD") {
57518
- const asset1Data = historicalBaseAssetPrices.find(
57519
- (a) => a.symbol === asset1
57520
- );
57521
- const asset2Data = historicalBaseAssetPrices.find(
57522
- (a) => a.symbol === asset2
57523
- );
57524
- const asset1PriceData = findClosestTimestampEntry(
57525
- asset1Data?.prices || [],
57526
- timestamp
57527
- );
57528
- const asset2PriceData = findClosestTimestampEntry(
57529
- asset2Data?.prices || [],
57530
- timestamp
57531
- );
57532
- if (asset1PriceData && asset2PriceData) {
57533
- const asset1UsdPrice = parseFloat(asset1PriceData.price);
57534
- const asset2UsdPrice = parseFloat(asset2PriceData.price);
57535
- prices[asset1][asset2] = asset2UsdPrice > 0 ? asset1UsdPrice / asset2UsdPrice : 0;
57536
- } else {
57537
- prices[asset1][asset2] = 0;
57538
- }
57724
+ } else if (asset1 === "USD") {
57725
+ prices[asset1][asset2] = usdPrices.get(asset2) || 0;
57726
+ } else if (asset2 === "USD") {
57727
+ prices[asset1][asset2] = usdPrices.get(asset1) || 0;
57728
+ } else {
57729
+ const asset1UsdPrice = usdPrices.get(asset1) || 0;
57730
+ const asset2UsdPrice = usdPrices.get(asset2) || 0;
57731
+ prices[asset1][asset2] = asset2UsdPrice > 0 ? asset1UsdPrice / asset2UsdPrice : 0;
57539
57732
  }
57540
57733
  });
57541
57734
  });
@@ -57552,7 +57745,7 @@ var getHistoricalTokenPrices = async () => {
57552
57745
  // functions/getUserAutopoolsHistory.ts
57553
57746
  var ONE_DAY_IN_MS = 24 * 60 * 60 * 1e3;
57554
57747
  function validateEnhancedUserHistoryEntry(entry) {
57555
- return entry && typeof entry === "object" && entry.date instanceof Date && typeof entry.timestamp === "string" && Array.isArray(entry.autopools) && entry.nav && typeof entry.nav.ETH === "number" && typeof entry.nav.USD === "number" && typeof entry.nav.PXETH === "number" && typeof entry.nav.USDC === "number" && Array.isArray(entry.events) && typeof entry.differential === "number";
57748
+ return entry && typeof entry === "object" && entry.date instanceof Date && typeof entry.timestamp === "string" && Array.isArray(entry.autopools) && entry.nav && typeof entry.nav.ETH === "number" && typeof entry.nav.USD === "number" && typeof entry.nav.PXETH === "number" && typeof entry.nav.USDC === "number" && typeof entry.nav.EURC === "number" && typeof entry.nav.USDT === "number" && Array.isArray(entry.events) && typeof entry.differential === "number";
57556
57749
  }
57557
57750
  var getUserAutopoolsHistory = async (address, autopoolsHistory, events, includeTestnet = false) => {
57558
57751
  if (!autopoolsHistory) {
@@ -57611,7 +57804,7 @@ var getUserAutopoolsHistory = async (address, autopoolsHistory, events, includeT
57611
57804
  Math.floor(sharesRatio * Number(SCALE))
57612
57805
  );
57613
57806
  const navBigInt = sharesRatioBigInt * BigInt(dayData.nav) / SCALE;
57614
- const navNum = (0, import_utils11.formatUnitsNum)(
57807
+ const navNum = (0, import_utils14.formatUnitsNum)(
57615
57808
  navBigInt,
57616
57809
  dayData.baseAsset.decimals
57617
57810
  );
@@ -57662,7 +57855,9 @@ var getUserAutopoolsHistory = async (address, autopoolsHistory, events, includeT
57662
57855
  ETH: 0,
57663
57856
  USD: 0,
57664
57857
  PXETH: 0,
57665
- USDC: 0
57858
+ USDC: 0,
57859
+ EURC: 0,
57860
+ USDT: 0
57666
57861
  },
57667
57862
  date: dayData.date,
57668
57863
  autopools: {}
@@ -57673,17 +57868,21 @@ var getUserAutopoolsHistory = async (address, autopoolsHistory, events, includeT
57673
57868
  acc[timestampKey].nav.ETH += dayData.nav.ETH;
57674
57869
  acc[timestampKey].nav.PXETH += dayData.nav.PXETH;
57675
57870
  acc[timestampKey].nav.USDC += dayData.nav.USDC;
57871
+ acc[timestampKey].nav.EURC += dayData.nav.EURC;
57872
+ acc[timestampKey].nav.USDT += dayData.nav.USDT;
57676
57873
  return acc;
57677
57874
  }, {});
57678
57875
  let finalAggregatedHistoryArray = Object.keys(aggregatedHistoryArray).map(
57679
57876
  (dateKey) => ({
57680
57877
  date: aggregatedHistoryArray[dateKey].date,
57681
- formattedDate: (0, import_utils11.formatDateToReadable)(aggregatedHistoryArray[dateKey].date),
57878
+ formattedDate: (0, import_utils14.formatDateToReadable)(aggregatedHistoryArray[dateKey].date),
57682
57879
  nav: {
57683
57880
  ETH: aggregatedHistoryArray[dateKey].nav.ETH,
57684
57881
  USD: aggregatedHistoryArray[dateKey].nav.USD,
57685
57882
  PXETH: aggregatedHistoryArray[dateKey].nav.PXETH,
57686
- USDC: aggregatedHistoryArray[dateKey].nav.USDC
57883
+ USDC: aggregatedHistoryArray[dateKey].nav.USDC,
57884
+ EURC: aggregatedHistoryArray[dateKey].nav.EURC,
57885
+ USDT: aggregatedHistoryArray[dateKey].nav.USDT
57687
57886
  },
57688
57887
  timestamp: aggregatedHistoryArray[dateKey].timestamp,
57689
57888
  autopools: Object.values(aggregatedHistoryArray[dateKey].autopools)
@@ -57697,7 +57896,9 @@ var getUserAutopoolsHistory = async (address, autopoolsHistory, events, includeT
57697
57896
  ETH: dayData.nav.ETH,
57698
57897
  USD: dayData.nav.USD,
57699
57898
  PXETH: dayData.nav.PXETH,
57700
- USDC: dayData.nav.USDC
57899
+ USDC: dayData.nav.USDC,
57900
+ EURC: dayData.nav.EURC,
57901
+ USDT: dayData.nav.USDT
57701
57902
  }
57702
57903
  };
57703
57904
  }
@@ -57709,7 +57910,7 @@ var getUserAutopoolsHistory = async (address, autopoolsHistory, events, includeT
57709
57910
  return eventDate.getTime() >= dayData.date.getTime() && eventDate.getTime() < dayData.date.getTime() + 24 * 60 * 60 * 1e3;
57710
57911
  });
57711
57912
  const differential = eventsForDay.reduce(
57712
- (sum, event) => sum + (0, import_utils11.formatEtherNum)(BigInt(event?.assetChange || 0n)),
57913
+ (sum, event) => sum + (0, import_utils14.formatEtherNum)(BigInt(event?.assetChange || 0n)),
57713
57914
  0
57714
57915
  );
57715
57916
  return {
@@ -57877,9 +58078,9 @@ var getUserCurveLP = async (wagmiConfig, {
57877
58078
  };
57878
58079
 
57879
58080
  // functions/getMultipleAutopoolRebalances.ts
57880
- var import_graph_cli7 = require("@tokemak/graph-cli");
58081
+ var import_graph_cli8 = require("@tokemak/graph-cli");
57881
58082
  var getMutlipleAutopoolRebalances = async (ids, chainId = 1) => {
57882
- const { GetMutlipleAutopoolRebalances } = (0, import_graph_cli7.getSdkByChainId)(chainId);
58083
+ const { GetMutlipleAutopoolRebalances } = (0, import_graph_cli8.getSdkByChainId)(chainId);
57883
58084
  const { autopools } = await GetMutlipleAutopoolRebalances({
57884
58085
  addresses: ids
57885
58086
  });
@@ -57889,12 +58090,12 @@ var getMutlipleAutopoolRebalances = async (ids, chainId = 1) => {
57889
58090
 
57890
58091
  // functions/getAutopoolDayData.ts
57891
58092
  var import_viem7 = require("viem");
57892
- var import_utils13 = require("@tokemak/utils");
58093
+ var import_utils16 = require("@tokemak/utils");
57893
58094
  var import_constants7 = require("@tokemak/constants");
57894
- var import_graph_cli8 = require("@tokemak/graph-cli");
58095
+ var import_graph_cli9 = require("@tokemak/graph-cli");
57895
58096
  var getAutopoolDayData = async (address, chainId = 1, startTimestamp = import_constants7.TOKEMAK_LAUNCH_TIMESTAMP) => {
57896
58097
  try {
57897
- const { GetAutopoolDayData } = (0, import_graph_cli8.getSdkByChainId)(chainId);
58098
+ const { GetAutopoolDayData } = (0, import_graph_cli9.getSdkByChainId)(chainId);
57898
58099
  const { autopoolDayDatas } = await GetAutopoolDayData({
57899
58100
  address,
57900
58101
  timestamp: startTimestamp
@@ -57903,10 +58104,10 @@ var getAutopoolDayData = async (address, chainId = 1, startTimestamp = import_co
57903
58104
  const navPerShare = autoPoolDayData.nav / autoPoolDayData.totalSupply;
57904
58105
  let baseApy = autoPoolDayData.autopoolApy;
57905
58106
  let rewarderApy = 0;
57906
- const formattedRewarder7DayMAApy = (0, import_utils13.formatEtherNum)(
58107
+ const formattedRewarder7DayMAApy = (0, import_utils16.formatEtherNum)(
57907
58108
  BigInt(Number(autoPoolDayData.rewarderDay7MAApy) || 0)
57908
58109
  );
57909
- const formattedRewarder30DayMAApy = (0, import_utils13.formatEtherNum)(
58110
+ const formattedRewarder30DayMAApy = (0, import_utils16.formatEtherNum)(
57910
58111
  BigInt(Number(autoPoolDayData.rewarderDay30MAApy) || 0)
57911
58112
  );
57912
58113
  if (formattedRewarder7DayMAApy) {
@@ -57985,12 +58186,12 @@ var getSystemConfig = async (wagmiConfig, { systemRegistry }) => {
57985
58186
  };
57986
58187
 
57987
58188
  // functions/getChainUserAutopools.tsx
57988
- var import_graph_cli9 = require("@tokemak/graph-cli");
58189
+ var import_graph_cli10 = require("@tokemak/graph-cli");
57989
58190
  var getChainUserAutopools = async ({
57990
58191
  address,
57991
58192
  chainId = 1
57992
58193
  }) => {
57993
- const { GetUserVaultInfo } = (0, import_graph_cli9.getSdkByChainId)(chainId);
58194
+ const { GetUserVaultInfo } = (0, import_graph_cli10.getSdkByChainId)(chainId);
57994
58195
  try {
57995
58196
  if (address) {
57996
58197
  const { userInfo } = await GetUserVaultInfo({
@@ -58006,13 +58207,13 @@ var getChainUserAutopools = async ({
58006
58207
  };
58007
58208
 
58008
58209
  // functions/getUserAutopools.ts
58009
- var import_utils15 = require("@tokemak/utils");
58210
+ var import_utils18 = require("@tokemak/utils");
58010
58211
  var import_tokenlist6 = require("@tokemak/tokenlist");
58011
58212
 
58012
58213
  // functions/getUserAutopool.tsx
58013
58214
  var import_viem8 = require("viem");
58014
58215
  var import_core9 = require("@wagmi/core");
58015
- var import_utils14 = require("@tokemak/utils");
58216
+ var import_utils17 = require("@tokemak/utils");
58016
58217
  var import_abis9 = require("@tokemak/abis");
58017
58218
  var getUserAutopool = async (wagmiConfig, {
58018
58219
  address,
@@ -58061,10 +58262,10 @@ var getUserAutopool = async (wagmiConfig, {
58061
58262
  args: [address],
58062
58263
  chainId: autopool?.chain?.chainId
58063
58264
  });
58064
- const stakedShares = (0, import_utils14.formatEtherNum)(stakedPoolShares);
58265
+ const stakedShares = (0, import_utils17.formatEtherNum)(stakedPoolShares);
58065
58266
  const stakedNav = stakedShares * (autopool?.navPerShare.baseAsset || 0);
58066
58267
  const stakedNavUsd = stakedShares * (autopool?.navPerShare.USD || 0);
58067
- const unstakedShares = (0, import_utils14.formatEtherNum)(unstakedPoolShares || 0n);
58268
+ const unstakedShares = (0, import_utils17.formatEtherNum)(unstakedPoolShares || 0n);
58068
58269
  const unstakedNav = unstakedShares * (autopool?.navPerShare.USD || 0);
58069
58270
  const unstakedNavUsd = unstakedShares * (autopool?.navPerShare.USD || 0);
58070
58271
  const totalShares = unstakedShares + stakedShares;
@@ -58085,7 +58286,7 @@ var getUserAutopool = async (wagmiConfig, {
58085
58286
  });
58086
58287
  pastRewarderBalances = pastRewards.map(({ result }, index) => {
58087
58288
  const balance = result;
58088
- const shares = (0, import_utils14.formatEtherNum)(result);
58289
+ const shares = (0, import_utils17.formatEtherNum)(result);
58089
58290
  const nav = shares * (autopool?.navPerShare.baseAsset || 0);
58090
58291
  const navUsd = shares * (autopool?.navPerShare.USD || 0);
58091
58292
  return {
@@ -58194,7 +58395,8 @@ var getUserAutopools = async ({
58194
58395
  let categories = {
58195
58396
  usd: { ...initialAutopoolsValue },
58196
58397
  eth: { ...initialAutopoolsValue },
58197
- crypto: { ...initialAutopoolsValue }
58398
+ crypto: { ...initialAutopoolsValue },
58399
+ stables: { ...initialAutopoolsValue }
58198
58400
  };
58199
58401
  const userAutopoolsWithData = userAutopools.map((userAutopool) => {
58200
58402
  const autopoolData = autopools.find(
@@ -58202,14 +58404,14 @@ var getUserAutopools = async ({
58202
58404
  );
58203
58405
  if (autopoolData) {
58204
58406
  const isDOLA = autopoolData.symbol === "autoDOLA" && userAutoDOLA;
58205
- const userShares = isDOLA ? userAutoDOLA?.totalShares : (0, import_utils15.formatEtherNum)(userAutopool?.totalShares);
58206
- const totalVaultShares = (0, import_utils15.formatEtherNum)(autopoolData?.totalSupply);
58407
+ const userShares = isDOLA ? userAutoDOLA?.totalShares : (0, import_utils18.formatEtherNum)(userAutopool?.totalShares);
58408
+ const totalVaultShares = (0, import_utils18.formatEtherNum)(autopoolData?.totalSupply);
58207
58409
  const userShareOfVault = userShares / totalVaultShares;
58208
- const totalDeposits = (0, import_utils15.formatUnitsNum)(
58410
+ const totalDeposits = (0, import_utils18.formatUnitsNum)(
58209
58411
  userActivity?.totals[userAutopool.vaultAddress]?.totalDeposits || 0n,
58210
58412
  autopoolData?.baseAsset.decimals
58211
58413
  );
58212
- const totalWithdrawals = (0, import_utils15.formatUnitsNum)(
58414
+ const totalWithdrawals = (0, import_utils18.formatUnitsNum)(
58213
58415
  userActivity?.totals[userAutopool.vaultAddress]?.totalWithdrawals || 0n,
58214
58416
  autopoolData?.baseAsset.decimals
58215
58417
  );
@@ -58218,7 +58420,7 @@ var getUserAutopools = async ({
58218
58420
  );
58219
58421
  let lastDeposit;
58220
58422
  if (poolEvents && poolEvents?.length > 0) {
58221
- lastDeposit = (0, import_utils15.convertTimestampToDate)(
58423
+ lastDeposit = (0, import_utils18.convertTimestampToDate)(
58222
58424
  poolEvents[poolEvents.length - 1].timestamp
58223
58425
  ).toLocaleDateString("en-US", {
58224
58426
  day: "2-digit",
@@ -58318,7 +58520,7 @@ var getUserAutopools = async ({
58318
58520
  totalWithdrawals: prev.totalWithdrawals + totalWithdrawals
58319
58521
  };
58320
58522
  const stakedBalance = isDOLA ? userAutoDOLA?.staked.balance : BigInt(userAutopool?.stakedShares);
58321
- const stakedShares = isDOLA ? userAutoDOLA?.staked.shares : (0, import_utils15.formatEtherNum)(stakedBalance);
58523
+ const stakedShares = isDOLA ? userAutoDOLA?.staked.shares : (0, import_utils18.formatEtherNum)(stakedBalance);
58322
58524
  const stakedNav = stakedShares * (autopoolData?.navPerShare.baseAsset || 0);
58323
58525
  const staked = convertBaseAssetToTokenPrices(
58324
58526
  stakedNav,
@@ -58326,7 +58528,7 @@ var getUserAutopools = async ({
58326
58528
  prices
58327
58529
  );
58328
58530
  const unstakedBalance = isDOLA ? userAutoDOLA?.unstaked.balance : BigInt(userAutopool?.walletShares);
58329
- const unstakedShares = isDOLA ? userAutoDOLA?.unstaked.shares : (0, import_utils15.formatEtherNum)(unstakedBalance);
58531
+ const unstakedShares = isDOLA ? userAutoDOLA?.unstaked.shares : (0, import_utils18.formatEtherNum)(unstakedBalance);
58330
58532
  const unstakedNav = unstakedShares * (autopoolData?.navPerShare.baseAsset || 0);
58331
58533
  const unstaked = convertBaseAssetToTokenPrices(
58332
58534
  unstakedNav,
@@ -58335,7 +58537,10 @@ var getUserAutopools = async ({
58335
58537
  );
58336
58538
  const stakedRatio = stakedShares / userShares;
58337
58539
  const unstakedRatio = 1 - stakedRatio;
58338
- const blendedApr = stakedRatio * autopoolData?.apr?.combined + unstakedRatio * autopoolData?.apr?.base;
58540
+ const isSilo = autopoolData?.symbol === "siloETH" || autopoolData?.symbol === "siloUSD";
58541
+ const baseApr = autopoolData?.apr?.base ?? 0;
58542
+ const stakedAprForBlend = isSilo ? baseApr : autopoolData?.apr?.combined ?? 0;
58543
+ const blendedApr = stakedRatio * stakedAprForBlend + unstakedRatio * baseApr;
58339
58544
  return {
58340
58545
  name: autopoolData?.name,
58341
58546
  symbol: autopoolData?.symbol,
@@ -58358,6 +58563,7 @@ var getUserAutopools = async ({
58358
58563
  nav: unstaked
58359
58564
  },
58360
58565
  useDenomination: autopoolData?.useDenomination,
58566
+ baseApr,
58361
58567
  blendedApr,
58362
58568
  rewardsClaimed: userAutopool?.rewardsClaimed,
58363
58569
  lastDeposit,
@@ -58522,14 +58728,14 @@ var getUserAutopools = async ({
58522
58728
 
58523
58729
  // functions/getUserTokenBalances.ts
58524
58730
  var import_viem9 = require("viem");
58525
- var import_chains7 = require("viem/chains");
58731
+ var import_chains6 = require("viem/chains");
58526
58732
  var networkToAlchemyUrl = (chainId, apiKey) => {
58527
58733
  switch (chainId) {
58528
- case import_chains7.mainnet.id:
58734
+ case import_chains6.mainnet.id:
58529
58735
  return `https://eth-mainnet.g.alchemy.com/v2/${apiKey}`;
58530
- case import_chains7.base.id:
58736
+ case import_chains6.base.id:
58531
58737
  return `https://base-mainnet.g.alchemy.com/v2/${apiKey}`;
58532
- case import_chains7.sonic.id:
58738
+ case import_chains6.sonic.id:
58533
58739
  return `https://sonic-mainnet.g.alchemy.com/v2/${apiKey}`;
58534
58740
  default:
58535
58741
  throw new Error("Unsupported network");
@@ -58591,10 +58797,10 @@ var getTokenList = async () => {
58591
58797
  };
58592
58798
 
58593
58799
  // functions/getTopAutopoolHolders.ts
58594
- var import_graph_cli10 = require("@tokemak/graph-cli");
58800
+ var import_graph_cli11 = require("@tokemak/graph-cli");
58595
58801
  var getTopAutopoolHolders = async (autopoolAddress, chainId = 1) => {
58596
58802
  try {
58597
- const { GetTopAutopoolHolders } = (0, import_graph_cli10.getSdkByChainId)(chainId);
58803
+ const { GetTopAutopoolHolders } = (0, import_graph_cli11.getSdkByChainId)(chainId);
58598
58804
  const { holders } = await GetTopAutopoolHolders({
58599
58805
  address: autopoolAddress
58600
58806
  });
@@ -58656,6 +58862,9 @@ var getUserActivity = async ({
58656
58862
  return mergedActivity;
58657
58863
  };
58658
58864
 
58865
+ // functions/getUserAutopoolsRewards.ts
58866
+ var import_viem11 = require("viem");
58867
+
58659
58868
  // functions/getChainUserAutopoolsRewards.ts
58660
58869
  var import_config8 = require("@tokemak/config");
58661
58870
  var import_core11 = require("@wagmi/core");
@@ -58684,7 +58893,11 @@ var getChainUserAutopoolsRewards = async (wagmiConfig, {
58684
58893
  if (!userRewards[autopool]) {
58685
58894
  userRewards[autopool] = {};
58686
58895
  }
58687
- userRewards[autopool][token.tokenAddress] = token.amount;
58896
+ if (userRewards[autopool][token.tokenAddress]) {
58897
+ userRewards[autopool][`${token.tokenAddress}-main`] = token.amount;
58898
+ } else {
58899
+ userRewards[autopool][`${token.tokenAddress}`] = token.amount;
58900
+ }
58688
58901
  });
58689
58902
  });
58690
58903
  return userRewards;
@@ -58694,29 +58907,66 @@ var getChainUserAutopoolsRewards = async (wagmiConfig, {
58694
58907
  };
58695
58908
 
58696
58909
  // functions/getUserAutopoolsRewards.ts
58697
- var import_utils19 = require("@tokemak/utils");
58910
+ var import_utils22 = require("@tokemak/utils");
58911
+ var import_tokenlist8 = require("@tokemak/tokenlist");
58912
+ var import_chains7 = require("viem/chains");
58698
58913
  var getUserAutopoolsRewards = async (wagmiConfig, {
58699
58914
  address,
58700
58915
  tokenPrices,
58916
+ autopools,
58701
58917
  includeTestnet = false
58702
58918
  }) => {
58703
58919
  const chains = getChainsForEnv({ includeTestnet });
58704
58920
  try {
58921
+ if (!autopools)
58922
+ throw new Error("No autopools found");
58705
58923
  const userRewards = await Promise.all(
58706
58924
  chains.map(
58707
58925
  (chain) => getChainUserAutopoolsRewards(wagmiConfig, {
58708
58926
  chainId: chain.chainId,
58709
- address,
58710
- tokenPrices
58927
+ address
58711
58928
  })
58712
58929
  )
58713
58930
  );
58714
58931
  const rewardsData = chains.map(({ chainId }, index) => {
58715
58932
  const chainUserRewards = userRewards[index] || {};
58933
+ const extraRewardsArray = Object.entries(chainUserRewards).flatMap(
58934
+ ([autopoolAddress, rewards]) => {
58935
+ const autopool = autopools.find(
58936
+ (autopool2) => (0, import_viem11.getAddress)(autopool2.poolAddress) === (0, import_viem11.getAddress)(autopoolAddress)
58937
+ );
58938
+ if (!autopool || !autopool.extraRewarders) {
58939
+ return [];
58940
+ }
58941
+ return autopool.extraRewarders.map((extraRewards2) => {
58942
+ const rewarderToken = (0, import_utils22.getToken)(
58943
+ extraRewards2.rewardToken?.id,
58944
+ autopool.chain?.chainId
58945
+ );
58946
+ const claimableAmount = rewards ? rewards[(0, import_viem11.getAddress)(extraRewards2.rewardToken?.id)] : 0n;
58947
+ let price = tokenPrices[rewarderToken.symbol] || 0;
58948
+ if (rewarderToken.symbol === "XSILO") {
58949
+ price = tokenPrices[import_tokenlist8.SILO_TOKEN.symbol] || 0;
58950
+ }
58951
+ const formattedAmount = (0, import_utils22.formatUnitsNum)(
58952
+ claimableAmount,
58953
+ rewarderToken.decimals || 18
58954
+ );
58955
+ return {
58956
+ address: (0, import_viem11.getAddress)(extraRewards2?.id),
58957
+ chainId,
58958
+ token: rewarderToken,
58959
+ amount: claimableAmount,
58960
+ formattedAmount,
58961
+ USD: formattedAmount * price
58962
+ };
58963
+ });
58964
+ }
58965
+ );
58716
58966
  const tokenRewards = {};
58717
58967
  Object.values(chainUserRewards).forEach((autopoolRewards) => {
58718
58968
  Object.entries(autopoolRewards).forEach(([tokenAddress, amount]) => {
58719
- const token = (0, import_utils19.getToken)(tokenAddress, chainId);
58969
+ const token = (0, import_utils22.getToken)(tokenAddress, chainId);
58720
58970
  const tokenSymbol = token.symbol;
58721
58971
  if (!tokenRewards[tokenSymbol]) {
58722
58972
  tokenRewards[tokenSymbol] = {
@@ -58732,8 +58982,11 @@ var getUserAutopoolsRewards = async (wagmiConfig, {
58732
58982
  });
58733
58983
  Object.entries(tokenRewards).forEach(
58734
58984
  ([tokenSymbol, { amount, decimals }]) => {
58735
- const price = tokenPrices[tokenSymbol] || 0;
58736
- const formattedAmount = (0, import_utils19.formatUnitsNum)(amount, decimals || 18);
58985
+ let price = tokenPrices[tokenSymbol] || 0;
58986
+ if (tokenSymbol === "XSILO") {
58987
+ price = tokenPrices[import_tokenlist8.SILO_TOKEN.symbol] || 0;
58988
+ }
58989
+ const formattedAmount = (0, import_utils22.formatUnitsNum)(amount, decimals || 18);
58737
58990
  tokenRewards[tokenSymbol] = {
58738
58991
  amount,
58739
58992
  formattedAmount,
@@ -58742,10 +58995,21 @@ var getUserAutopoolsRewards = async (wagmiConfig, {
58742
58995
  };
58743
58996
  }
58744
58997
  );
58998
+ if (Object.keys(tokenRewards).includes("undefined") && chainId === import_chains7.plasma.id) {
58999
+ const undefinedToken = tokenRewards["undefined"];
59000
+ let price = tokenPrices.TOKE || 0;
59001
+ tokenRewards["TOKE"] = {
59002
+ ...undefinedToken,
59003
+ USD: undefinedToken.formattedAmount * price,
59004
+ logoURI: import_tokenlist8.TOKE_TOKEN.logoURI
59005
+ };
59006
+ delete tokenRewards["undefined"];
59007
+ }
58745
59008
  return {
58746
59009
  chainId,
58747
59010
  autopools: chainUserRewards,
58748
- rewards: tokenRewards
59011
+ rewards: tokenRewards,
59012
+ extraRewards: extraRewardsArray
58749
59013
  };
58750
59014
  });
58751
59015
  const rewardsByToken = {};
@@ -58770,14 +59034,21 @@ var getUserAutopoolsRewards = async (wagmiConfig, {
58770
59034
  (acc, { USD }) => acc + USD,
58771
59035
  0
58772
59036
  );
59037
+ const extraRewards = rewardsData.flatMap(
59038
+ ({ extraRewards: extraRewards2 }) => extraRewards2
59039
+ );
59040
+ const hasRewards = totalRewardsUSD > 0 || extraRewards.some((extraReward) => extraReward.USD > 0);
58773
59041
  return {
58774
59042
  chains: {
58775
59043
  ...Object.fromEntries(
58776
59044
  rewardsData.map(({ chainId, ...data }) => [chainId, data])
58777
59045
  )
58778
59046
  },
59047
+ tokeRewards: rewardsByToken.TOKE,
59048
+ extraRewards,
58779
59049
  rewardsByToken,
58780
- totalRewardsUSD
59050
+ totalRewardsUSD,
59051
+ hasRewards
58781
59052
  };
58782
59053
  } catch (e) {
58783
59054
  console.error(e);
@@ -58785,8 +59056,8 @@ var getUserAutopoolsRewards = async (wagmiConfig, {
58785
59056
  };
58786
59057
 
58787
59058
  // functions/getAmountWithdrawn.ts
58788
- var import_viem12 = require("viem");
58789
- var import_utils21 = require("@tokemak/utils");
59059
+ var import_viem13 = require("viem");
59060
+ var import_utils24 = require("@tokemak/utils");
58790
59061
 
58791
59062
  // functions/getSwapQuote.ts
58792
59063
  var import_constants8 = require("@tokemak/constants");
@@ -58816,17 +59087,20 @@ var getAutopilotRouter = async (wagmiConfig, { chainId }) => await getAddressFro
58816
59087
 
58817
59088
  // functions/getSwapQuote.ts
58818
59089
  var import_config10 = require("@tokemak/config");
58819
- var import_tokenlist8 = require("@tokemak/tokenlist");
59090
+ var import_tokenlist9 = require("@tokemak/tokenlist");
58820
59091
  var import_chains8 = require("viem/chains");
58821
59092
  var getSwapQuote = async (config, { chainId, ...params }) => {
58822
59093
  try {
58823
59094
  if (!params.sellToken || !params.buyToken) {
58824
59095
  throw new Error("Sell token and buy token are required");
58825
59096
  }
58826
- if (params.sellToken === import_tokenlist8.ETH_TOKEN.address) {
59097
+ if (params.sellToken === import_tokenlist9.ETH_TOKEN.address) {
58827
59098
  params.sellToken = (0, import_config10.getCoreConfig)(chainId).weth;
58828
59099
  if (chainId === import_chains8.sonic.id) {
58829
- params.sellToken = import_tokenlist8.WS_TOKEN.address;
59100
+ params.sellToken = import_tokenlist9.WS_TOKEN.address;
59101
+ }
59102
+ if (chainId === import_chains8.plasma.id) {
59103
+ params.sellToken = import_tokenlist9.WXPL_TOKEN.address;
58830
59104
  }
58831
59105
  }
58832
59106
  const sellAmount = params.sellAmount.toString();
@@ -58861,7 +59135,7 @@ var import_core13 = require("@wagmi/core");
58861
59135
  var import_abis12 = require("@tokemak/abis");
58862
59136
  var import_config11 = require("@tokemak/config");
58863
59137
  var import_autopilot_swap_route_calc = __toESM(require_dist2(), 1);
58864
- var import_viem11 = require("viem");
59138
+ var import_viem12 = require("viem");
58865
59139
  var import_constants9 = require("@tokemak/constants");
58866
59140
  var placeholderAddress = "0x8b4334d4812c530574bd4f2763fcd22de94a969b";
58867
59141
  var getDynamicSwap = async ({
@@ -58936,7 +59210,7 @@ var getDynamicSwap = async ({
58936
59210
  account: user || placeholderAddress
58937
59211
  });
58938
59212
  } catch (e) {
58939
- if (e instanceof import_viem11.ContractFunctionExecutionError && e.cause instanceof import_viem11.ContractFunctionRevertedError && e.cause.data?.errorName === "PreviewRedeemWithRoutesResult") {
59213
+ if (e instanceof import_viem12.ContractFunctionExecutionError && e.cause instanceof import_viem12.ContractFunctionRevertedError && e.cause.data?.errorName === "PreviewRedeemWithRoutesResult") {
58940
59214
  previewRedeem = e.cause.data?.args?.[0];
58941
59215
  }
58942
59216
  }
@@ -58965,7 +59239,7 @@ var getDynamicSwap = async ({
58965
59239
  };
58966
59240
 
58967
59241
  // functions/getAmountWithdrawn.ts
58968
- var import_tokenlist9 = require("@tokemak/tokenlist");
59242
+ var import_tokenlist10 = require("@tokemak/tokenlist");
58969
59243
  var import_config12 = require("@tokemak/config");
58970
59244
  var import_core14 = require("@wagmi/core");
58971
59245
  var import_abis13 = require("@tokemak/abis");
@@ -58997,13 +59271,13 @@ var getAmountWithdrawn = async ({
58997
59271
  let quote;
58998
59272
  let convertedAssets;
58999
59273
  if (!!dynamicSwap?.previewRedeem) {
59000
- const minAmountWithSlippage = (0, import_utils21.calculateMinAmountWithSlippage)(
59274
+ const minAmountWithSlippage = (0, import_utils24.calculateMinAmountWithSlippage)(
59001
59275
  dynamicSwap?.previewRedeem,
59002
59276
  slippage
59003
59277
  );
59004
- let minAmount = (0, import_viem12.formatUnits)(minAmountWithSlippage, decimals);
59278
+ let minAmount = (0, import_viem13.formatUnits)(minAmountWithSlippage, decimals);
59005
59279
  if (isSwap) {
59006
- if (buyToken === import_tokenlist9.ETH_TOKEN.address) {
59280
+ if (buyToken === import_tokenlist10.ETH_TOKEN.address) {
59007
59281
  const weth = (0, import_config12.getCoreConfig)(chainId).weth;
59008
59282
  buyToken = weth;
59009
59283
  }
@@ -59021,13 +59295,13 @@ var getAmountWithdrawn = async ({
59021
59295
  buyToken,
59022
59296
  sellToken,
59023
59297
  sellAmount: dynamicSwap?.previewRedeem,
59024
- slippageBps: (0, import_utils21.convertNumToBps)(slippage),
59298
+ slippageBps: (0, import_utils24.convertNumToBps)(slippage),
59025
59299
  chainId,
59026
59300
  includeSources: "0xV2",
59027
59301
  sellAll: true
59028
59302
  });
59029
59303
  if (quote) {
59030
- minAmount = (0, import_viem12.formatUnits)(BigInt(quote?.minBuyAmount), decimals);
59304
+ minAmount = (0, import_viem13.formatUnits)(BigInt(quote?.minBuyAmount), decimals);
59031
59305
  } else {
59032
59306
  throw new Error("No quote found");
59033
59307
  }
@@ -59049,7 +59323,7 @@ var getAmountWithdrawn = async ({
59049
59323
  // functions/getAmountDeposited.ts
59050
59324
  var import_core15 = require("@wagmi/core");
59051
59325
  var import_abis14 = require("@tokemak/abis");
59052
- var import_utils22 = require("@tokemak/utils");
59326
+ var import_utils25 = require("@tokemak/utils");
59053
59327
  var getAmountDeposited = async ({
59054
59328
  address,
59055
59329
  chainId,
@@ -59070,13 +59344,13 @@ var getAmountDeposited = async ({
59070
59344
  chainId
59071
59345
  });
59072
59346
  if (!isSwap) {
59073
- let minAmountWithSlippage = (0, import_utils22.calculateMinAmountWithSlippage)(
59347
+ let minAmountWithSlippage = (0, import_utils25.calculateMinAmountWithSlippage)(
59074
59348
  previewDeposit,
59075
59349
  slippage
59076
59350
  );
59077
- return (0, import_utils22.formatEtherNum)(minAmountWithSlippage);
59351
+ return (0, import_utils25.formatEtherNum)(minAmountWithSlippage);
59078
59352
  } else {
59079
- return (0, import_utils22.formatEtherNum)(previewDeposit);
59353
+ return (0, import_utils25.formatEtherNum)(previewDeposit);
59080
59354
  }
59081
59355
  } catch (e) {
59082
59356
  console.error(e);
@@ -59088,7 +59362,7 @@ var getAmountDeposited = async ({
59088
59362
  // functions/getBridgeFee.ts
59089
59363
  var import_core16 = require("@wagmi/core");
59090
59364
  var import_abis15 = require("@tokemak/abis");
59091
- var import_viem13 = require("viem");
59365
+ var import_viem14 = require("viem");
59092
59366
 
59093
59367
  // ../../node_modules/@ethersproject/logger/lib.esm/_version.js
59094
59368
  var version = "logger/5.8.0";
@@ -59860,7 +60134,7 @@ var getBridgeFee = async (wagmiConfig, {
59860
60134
  const minAmountLD = amount / factor * factor;
59861
60135
  const sendParams = {
59862
60136
  dstEid: eid,
59863
- to: (0, import_viem13.toHex)(addressToBytes32(from)),
60137
+ to: (0, import_viem14.toHex)(addressToBytes32(from)),
59864
60138
  amountLD: amount,
59865
60139
  minAmountLD,
59866
60140
  extraOptions: "0x",
@@ -59938,9 +60212,9 @@ var waitForMessageReceived = async ({
59938
60212
  // functions/getChainUserSToke.ts
59939
60213
  var import_abis17 = require("@tokemak/abis");
59940
60214
  var import_config13 = require("@tokemak/config");
59941
- var import_utils23 = require("@tokemak/utils");
60215
+ var import_utils26 = require("@tokemak/utils");
59942
60216
  var import_core18 = require("@wagmi/core");
59943
- var import_viem14 = require("viem");
60217
+ var import_viem15 = require("viem");
59944
60218
  var import_chains9 = require("viem/chains");
59945
60219
 
59946
60220
  // functions/getCurrentCycleId.ts
@@ -59959,7 +60233,7 @@ var getCurrentCycleId = async (wagmiConfig, {
59959
60233
  };
59960
60234
 
59961
60235
  // functions/getChainUserSToke.ts
59962
- var import_graph_cli11 = require("@tokemak/graph-cli");
60236
+ var import_graph_cli12 = require("@tokemak/graph-cli");
59963
60237
  var getChainUserSToke = async (wagmiConfig, {
59964
60238
  address,
59965
60239
  tokePrice,
@@ -59969,7 +60243,7 @@ var getChainUserSToke = async (wagmiConfig, {
59969
60243
  const { stoke } = (0, import_config13.getCoreConfig)(chainId);
59970
60244
  const cycleIndex = await getCurrentCycleId(wagmiConfig, { chainId, stoke });
59971
60245
  if (address && cycleIndex && stoke && tokePrice) {
59972
- const { GetUserSTokeBalance } = (0, import_graph_cli11.getSdkByChainId)(
60246
+ const { GetUserSTokeBalance } = (0, import_graph_cli12.getSdkByChainId)(
59973
60247
  chainId
59974
60248
  );
59975
60249
  const { accountBalanceV1S } = await GetUserSTokeBalance({
@@ -60014,8 +60288,8 @@ var getChainUserSToke = async (wagmiConfig, {
60014
60288
  if (withdrawalAmount > 0n && cycleIndex >= withdrawalMinCycle) {
60015
60289
  balanceExcludingWithdrawal = balanceExcludingWithdrawal - withdrawalAmount;
60016
60290
  }
60017
- const withdrawalAmountUsd = (0, import_utils23.formatCurrency)(
60018
- (0, import_utils23.formatEtherNum)(withdrawalAmount) * tokePrice
60291
+ const withdrawalAmountUsd = (0, import_utils26.formatCurrency)(
60292
+ (0, import_utils26.formatEtherNum)(withdrawalAmount) * tokePrice
60019
60293
  );
60020
60294
  const lockDuration = Number(depositLockDuration);
60021
60295
  const lockCycle = Number(depositLockCycle);
@@ -60036,16 +60310,16 @@ var getChainUserSToke = async (wagmiConfig, {
60036
60310
  const withdrawAvailable = lockRenew - 1;
60037
60311
  const hasAddedLockedToke = depositAmount > 0n && depositAmount > rolloverDepositAmount;
60038
60312
  const addedLockedToke = depositAmount - rolloverDepositAmount;
60039
- const balanceUSD = (0, import_utils23.formatCurrency)(
60040
- Number((0, import_viem14.formatEther)(balanceExcludingWithdrawal)) * tokePrice
60313
+ const balanceUSD = (0, import_utils26.formatCurrency)(
60314
+ Number((0, import_viem15.formatEther)(balanceExcludingWithdrawal)) * tokePrice
60041
60315
  );
60042
- const balanceExcludingWithdrawalUsd = (0, import_utils23.formatCurrency)(
60043
- (0, import_utils23.formatEtherNum)(balanceExcludingWithdrawal) * tokePrice
60316
+ const balanceExcludingWithdrawalUsd = (0, import_utils26.formatCurrency)(
60317
+ (0, import_utils26.formatEtherNum)(balanceExcludingWithdrawal) * tokePrice
60044
60318
  );
60045
60319
  const isUnlockRequestAvailable = currentCycle === withdrawAvailable;
60046
60320
  const hasRequestedUnlock = withdrawalAmount > 0n;
60047
- const unlockRequestPeriodStartUnix = (0, import_utils23.convertChainCycleToUnix)(withdrawAvailable, chainId) - Date.now() / 1e3;
60048
- const unlockRequestPeriodEndUnix = (0, import_utils23.convertChainCycleToUnix)(lockRenew, chainId) - Date.now() / 1e3;
60321
+ const unlockRequestPeriodStartUnix = (0, import_utils26.convertChainCycleToUnix)(withdrawAvailable, chainId) - Date.now() / 1e3;
60322
+ const unlockRequestPeriodEndUnix = (0, import_utils26.convertChainCycleToUnix)(lockRenew, chainId) - Date.now() / 1e3;
60049
60323
  const hasBalance = balance > 0n;
60050
60324
  const hasBalanceExcludingWithdrawal = balanceExcludingWithdrawal > 0n;
60051
60325
  const hasUnlockableBalance = withdrawalMinCycle <= currentCycle && withdrawalAmount > 0n;
@@ -60055,8 +60329,8 @@ var getChainUserSToke = async (wagmiConfig, {
60055
60329
  lockDurationInMonths = lockDuration - 1;
60056
60330
  }
60057
60331
  const unlockPeriodDateRangeArray = [
60058
- new Date((0, import_utils23.convertChainCycleToUnix)(withdrawAvailable, chainId) * 1e3),
60059
- new Date((0, import_utils23.convertChainCycleToUnix)(lockRenew, chainId) * 1e3)
60332
+ new Date((0, import_utils26.convertChainCycleToUnix)(withdrawAvailable, chainId) * 1e3),
60333
+ new Date((0, import_utils26.convertChainCycleToUnix)(lockRenew, chainId) * 1e3)
60060
60334
  ];
60061
60335
  const {
60062
60336
  unlockPeriodDateRange,
@@ -60068,18 +60342,18 @@ var getChainUserSToke = async (wagmiConfig, {
60068
60342
  unlockPeriodDateRangeArray,
60069
60343
  chainId === import_chains9.sepolia.id ? "time" : "date"
60070
60344
  );
60071
- const totalActiveUserCredits = (0, import_utils23.formatEtherNum)(balanceExcludingWithdrawal) * lockDurationInMonths;
60072
- const totalUserCredits = (0, import_utils23.formatEtherNum)(balance) * lockDurationInMonths;
60345
+ const totalActiveUserCredits = (0, import_utils26.formatEtherNum)(balanceExcludingWithdrawal) * lockDurationInMonths;
60346
+ const totalUserCredits = (0, import_utils26.formatEtherNum)(balance) * lockDurationInMonths;
60073
60347
  return {
60074
60348
  balance,
60075
60349
  balanceUSD,
60076
- balanceExcludingWithdrawal: hasBalance ? (0, import_viem14.formatEther)(balanceExcludingWithdrawal) : "0.00",
60350
+ balanceExcludingWithdrawal: hasBalance ? (0, import_viem15.formatEther)(balanceExcludingWithdrawal) : "0.00",
60077
60351
  balanceExcludingWithdrawalUsd,
60078
60352
  hasBalanceExcludingWithdrawal,
60079
- timeLeftBeforeUnlockRequestAvailable: (0, import_utils23.convertSecondsToRemainingTime)(
60353
+ timeLeftBeforeUnlockRequestAvailable: (0, import_utils26.convertSecondsToRemainingTime)(
60080
60354
  unlockRequestPeriodStartUnix
60081
60355
  ),
60082
- timeLeftBeforeUnlockRequestUnavailable: (0, import_utils23.convertSecondsToRemainingTime)(
60356
+ timeLeftBeforeUnlockRequestUnavailable: (0, import_utils26.convertSecondsToRemainingTime)(
60083
60357
  unlockRequestPeriodEndUnix
60084
60358
  ),
60085
60359
  withdrawalAmount,
@@ -60096,7 +60370,7 @@ var getChainUserSToke = async (wagmiConfig, {
60096
60370
  unlockRenewalDate,
60097
60371
  lockDurationInMonths,
60098
60372
  boost: lockDuration,
60099
- points: (0, import_utils23.formatEtherNum)(balanceExcludingWithdrawal) * lockDuration,
60373
+ points: (0, import_utils26.formatEtherNum)(balanceExcludingWithdrawal) * lockDuration,
60100
60374
  totalActiveCredits: totalActiveUserCredits,
60101
60375
  totalCredits: totalUserCredits
60102
60376
  };
@@ -60108,7 +60382,7 @@ var getChainUserSToke = async (wagmiConfig, {
60108
60382
  };
60109
60383
 
60110
60384
  // functions/getUserSToke.ts
60111
- var import_utils25 = require("@tokemak/utils");
60385
+ var import_utils28 = require("@tokemak/utils");
60112
60386
  var getUserSToke = async (wagmiConfig, {
60113
60387
  address,
60114
60388
  tokePrice,
@@ -60135,8 +60409,8 @@ var getUserSToke = async (wagmiConfig, {
60135
60409
  }
60136
60410
  return acc;
60137
60411
  }, 0n);
60138
- const totalBalance = (0, import_utils25.formatEtherNum)(totalBalanceRaw || 0n);
60139
- const totalBalanceUsd = (0, import_utils25.formatCurrency)(totalBalance * tokePrice);
60412
+ const totalBalance = (0, import_utils28.formatEtherNum)(totalBalanceRaw || 0n);
60413
+ const totalBalanceUsd = (0, import_utils28.formatCurrency)(totalBalance * tokePrice);
60140
60414
  const hasBalance = totalBalance > 0;
60141
60415
  return {
60142
60416
  chains: { ...userSToke },
@@ -60150,12 +60424,12 @@ var getUserSToke = async (wagmiConfig, {
60150
60424
  };
60151
60425
 
60152
60426
  // functions/getChainSToke.ts
60153
- var import_viem15 = require("viem");
60427
+ var import_viem16 = require("viem");
60154
60428
  var import_core19 = require("@wagmi/core");
60155
60429
  var import_abis18 = require("@tokemak/abis");
60156
- var import_utils27 = require("@tokemak/utils");
60430
+ var import_utils30 = require("@tokemak/utils");
60157
60431
  var import_config14 = require("@tokemak/config");
60158
- var import_utils28 = require("@tokemak/utils");
60432
+ var import_utils31 = require("@tokemak/utils");
60159
60433
  var getChainSToke = async (wagmiConfig, {
60160
60434
  tokePrice,
60161
60435
  chainId
@@ -60180,16 +60454,16 @@ var getChainSToke = async (wagmiConfig, {
60180
60454
  }
60181
60455
  ]
60182
60456
  });
60183
- const tvl = Number((0, import_viem15.formatEther)(totalSupply || 0n)) * tokePrice;
60184
- const secondsLeftBeforeNextCycle = (0, import_utils27.convertChainCycleToUnix)(Number(currentCycle) + 1, chainId) - Date.now() / 1e3;
60457
+ const tvl = Number((0, import_viem16.formatEther)(totalSupply || 0n)) * tokePrice;
60458
+ const secondsLeftBeforeNextCycle = (0, import_utils30.convertChainCycleToUnix)(Number(currentCycle) + 1, chainId) - Date.now() / 1e3;
60185
60459
  return {
60186
60460
  rawTotalSupply: totalSupply,
60187
- totalSupply: (0, import_utils27.formatLargeNumber)((0, import_viem15.formatEther)(totalSupply || 0n)),
60188
- tvl: (0, import_utils27.formatTVL)(tvl),
60461
+ totalSupply: (0, import_utils30.formatLargeNumber)((0, import_viem16.formatEther)(totalSupply || 0n)),
60462
+ tvl: (0, import_utils30.formatTVL)(tvl),
60189
60463
  rawTVL: tvl,
60190
60464
  currentCycle,
60191
- chain: (0, import_utils28.getNetwork)(chainId),
60192
- timeBeforeNextCycle: (0, import_utils27.convertSecondsToRemainingTime)(
60465
+ chain: (0, import_utils31.getNetwork)(chainId),
60466
+ timeBeforeNextCycle: (0, import_utils30.convertSecondsToRemainingTime)(
60193
60467
  secondsLeftBeforeNextCycle
60194
60468
  )
60195
60469
  };
@@ -60200,8 +60474,8 @@ var getChainSToke = async (wagmiConfig, {
60200
60474
  };
60201
60475
 
60202
60476
  // functions/getSToke.ts
60203
- var import_utils29 = require("@tokemak/utils");
60204
- var import_viem16 = require("viem");
60477
+ var import_utils32 = require("@tokemak/utils");
60478
+ var import_viem17 = require("viem");
60205
60479
  var getSToke = async (wagmiConfig, {
60206
60480
  tokePrice,
60207
60481
  includeTestnet = false
@@ -60220,14 +60494,14 @@ var getSToke = async (wagmiConfig, {
60220
60494
  }
60221
60495
  return acc;
60222
60496
  }, 0n);
60223
- const totalSupply = (0, import_utils29.formatLargeNumber)((0, import_viem16.formatEther)(totalSupplyBigInt || 0n));
60497
+ const totalSupply = (0, import_utils32.formatLargeNumber)((0, import_viem17.formatEther)(totalSupplyBigInt || 0n));
60224
60498
  let tvlNum = Object.values(sToke).reduce((acc, item) => {
60225
60499
  if (item && item.rawTVL) {
60226
60500
  return acc + item.rawTVL;
60227
60501
  }
60228
60502
  return acc;
60229
60503
  }, 0);
60230
- const tvl = (0, import_utils29.formatTVL)(tvlNum);
60504
+ const tvl = (0, import_utils32.formatTVL)(tvlNum);
60231
60505
  return { totalSupply, tvl, rawTVL: tvlNum, chains: { ...sToke } };
60232
60506
  } catch (e) {
60233
60507
  console.error(e);
@@ -60279,8 +60553,8 @@ var getChainCycleRolloverBlockNumber = async (wagmiConfig, {
60279
60553
  };
60280
60554
 
60281
60555
  // functions/getChainUserSTokeVotes.ts
60282
- var import_utils32 = require("@tokemak/utils");
60283
- var import_graph_cli12 = require("@tokemak/graph-cli");
60556
+ var import_utils35 = require("@tokemak/utils");
60557
+ var import_graph_cli13 = require("@tokemak/graph-cli");
60284
60558
  var getChainUserSTokeVotes = async ({
60285
60559
  address,
60286
60560
  chainId = 1,
@@ -60289,7 +60563,7 @@ var getChainUserSTokeVotes = async ({
60289
60563
  }) => {
60290
60564
  try {
60291
60565
  if (address && stokeVotes) {
60292
- const { GetUserSTokeVotes, GetUserSTokeBalance } = (0, import_graph_cli12.getSdkByChainId)(chainId);
60566
+ const { GetUserSTokeVotes, GetUserSTokeBalance } = (0, import_graph_cli13.getSdkByChainId)(chainId);
60293
60567
  const { userVotes } = await GetUserSTokeVotes({
60294
60568
  address: address.toLowerCase()
60295
60569
  });
@@ -60302,10 +60576,10 @@ var getChainUserSTokeVotes = async ({
60302
60576
  subgraphUserVotesData?.pools || [],
60303
60577
  subgraphUserVotesData?.weights || []
60304
60578
  );
60305
- const stakedToke = (0, import_utils32.formatEtherNum)(
60579
+ const stakedToke = (0, import_utils35.formatEtherNum)(
60306
60580
  BigInt(subgraphAccountVotesBalance?.amount || 0n)
60307
60581
  );
60308
- const totalUserVotes = (0, import_utils32.formatEtherNum)(
60582
+ const totalUserVotes = (0, import_utils35.formatEtherNum)(
60309
60583
  BigInt(subgraphAccountVotesBalance?.points || 0n)
60310
60584
  );
60311
60585
  const autopools = {};
@@ -60393,21 +60667,21 @@ var getUserSTokeVotes = async ({
60393
60667
 
60394
60668
  // functions/getChainSTokeVotes.ts
60395
60669
  var import_config15 = require("@tokemak/config");
60396
- var import_utils35 = require("@tokemak/utils");
60397
- var import_viem17 = require("viem");
60398
- var import_graph_cli13 = require("@tokemak/graph-cli");
60670
+ var import_utils38 = require("@tokemak/utils");
60671
+ var import_viem18 = require("viem");
60672
+ var import_graph_cli14 = require("@tokemak/graph-cli");
60399
60673
  var getChainSTokeVotes = async ({
60400
60674
  chainId,
60401
60675
  includeTestnet = false
60402
60676
  }) => {
60403
- const { GetSTokeVotes } = (0, import_graph_cli13.getSdkByChainId)(chainId);
60677
+ const { GetSTokeVotes } = (0, import_graph_cli14.getSdkByChainId)(chainId);
60404
60678
  const { accTokeVoteWeights, voteStatuses } = await GetSTokeVotes();
60405
60679
  const autopoolRawVotes = voteStatuses[0];
60406
60680
  const globalVotes = accTokeVoteWeights[0];
60407
60681
  const globalVoted = BigInt(globalVotes.voted);
60408
60682
  const globalNotVoted = BigInt(globalVotes.notVoted);
60409
60683
  const whitelistedPools = includeTestnet ? autopoolRawVotes?.pools || [] : (autopoolRawVotes?.pools || []).filter(
60410
- (pool) => import_config15.AUTOPOOLS_WHITELIST_PROD.includes((0, import_viem17.getAddress)(pool))
60684
+ (pool) => import_config15.AUTOPOOLS_WHITELIST_PROD.includes((0, import_viem18.getAddress)(pool))
60411
60685
  );
60412
60686
  const poolCount = whitelistedPools.length;
60413
60687
  const perPoolNotVoted = !!poolCount ? globalNotVoted / BigInt(poolCount) : 0n;
@@ -60424,13 +60698,13 @@ var getChainSTokeVotes = async ({
60424
60698
  updatedPoints
60425
60699
  );
60426
60700
  const globalSystemVotes = globalVoted + globalNotVoted;
60427
- const totalSystemVotesNum = (0, import_utils35.formatEtherNum)(globalSystemVotes);
60701
+ const totalSystemVotesNum = (0, import_utils38.formatEtherNum)(globalSystemVotes);
60428
60702
  const formattedAutopoolVotes = Object.fromEntries(
60429
60703
  Object.entries(autopoolVotes).filter(
60430
60704
  ([poolAddress]) => includeTestnet ? true : whitelistedPools.includes(poolAddress)
60431
60705
  ).map(([poolAddress, rawVote]) => {
60432
- const formattedVote = (0, import_utils35.formatLargeNumber)(
60433
- (0, import_utils35.formatEtherNum)(BigInt(rawVote))
60706
+ const formattedVote = (0, import_utils38.formatLargeNumber)(
60707
+ (0, import_utils38.formatEtherNum)(BigInt(rawVote))
60434
60708
  );
60435
60709
  return [
60436
60710
  poolAddress,
@@ -60445,7 +60719,7 @@ var getChainSTokeVotes = async ({
60445
60719
  globalSystemVotes
60446
60720
  },
60447
60721
  totalSystemVotesNum,
60448
- totalSystemVotes: (0, import_utils35.formatLargeNumber)(totalSystemVotesNum),
60722
+ totalSystemVotes: (0, import_utils38.formatLargeNumber)(totalSystemVotesNum),
60449
60723
  autopoolVotes: formattedAutopoolVotes
60450
60724
  };
60451
60725
  };
@@ -60470,14 +60744,14 @@ var getSTokeVotes = async ({
60470
60744
 
60471
60745
  // functions/getChainSTokeRewards.ts
60472
60746
  var import_config16 = require("@tokemak/config");
60473
- var import_viem18 = require("viem");
60474
- var import_utils37 = require("@tokemak/utils");
60475
- var import_graph_cli14 = require("@tokemak/graph-cli");
60747
+ var import_viem19 = require("viem");
60748
+ var import_utils40 = require("@tokemak/utils");
60749
+ var import_graph_cli15 = require("@tokemak/graph-cli");
60476
60750
  var getChainSTokeRewards = async ({
60477
60751
  chainId
60478
60752
  }) => {
60479
60753
  try {
60480
- const { GetSTokeRewards } = (0, import_graph_cli14.getSdkByChainId)(chainId);
60754
+ const { GetSTokeRewards } = (0, import_graph_cli15.getSdkByChainId)(chainId);
60481
60755
  const { poolRewardsBalances } = await GetSTokeRewards();
60482
60756
  const allPoolRewardsBalanceDayDatas = await paginateQuery(
60483
60757
  GetSTokeRewards,
@@ -60495,9 +60769,9 @@ var getChainSTokeRewards = async ({
60495
60769
  if (!whitelistedPools.includes(pool.id.toLowerCase())) {
60496
60770
  continue;
60497
60771
  }
60498
- const convertedBalance = (0, import_utils37.formatEtherNum)(pool.balance);
60499
- const convertedBalanceUSD = Number((0, import_viem18.formatUnits)(pool.balanceUSD, 8));
60500
- const convertedApr = (0, import_utils37.formatEtherNum)(pool.currentAprPerCredit);
60772
+ const convertedBalance = (0, import_utils40.formatEtherNum)(pool.balance);
60773
+ const convertedBalanceUSD = Number((0, import_viem19.formatUnits)(pool.balanceUSD, 8));
60774
+ const convertedApr = (0, import_utils40.formatEtherNum)(pool.currentAprPerCredit);
60501
60775
  if (minApr === null || convertedApr < minApr) {
60502
60776
  minApr = convertedApr;
60503
60777
  }
@@ -60570,7 +60844,7 @@ var getSTokeRewards = async ({
60570
60844
 
60571
60845
  // functions/getChainUserSTokeRewards.ts
60572
60846
  var import_config17 = require("@tokemak/config");
60573
- var import_utils40 = require("@tokemak/utils");
60847
+ var import_utils43 = require("@tokemak/utils");
60574
60848
  var getChainUserSTokeRewards = async (wagmiConfig, {
60575
60849
  address,
60576
60850
  chainId,
@@ -60621,14 +60895,14 @@ var getChainUserSTokeRewards = async (wagmiConfig, {
60621
60895
  throw fallbackError;
60622
60896
  }
60623
60897
  }
60624
- const claimableNum = (0, import_utils40.formatEtherNum)(tokeRewards?.claimable || 0n);
60898
+ const claimableNum = (0, import_utils43.formatEtherNum)(tokeRewards?.claimable || 0n);
60625
60899
  const claimableUsd = tokePrice * claimableNum;
60626
60900
  const hasClaimable = claimableNum > 0n;
60627
- const pendingRewards = (0, import_utils40.formatEtherNum)(
60901
+ const pendingRewards = (0, import_utils43.formatEtherNum)(
60628
60902
  tokeRewards?.rewardsPayload.breakdown?.totalRewardAmount || 0n
60629
60903
  );
60630
60904
  const pendingRewardsUsd = tokePrice * pendingRewards;
60631
- const totalRewardsReceived = (0, import_utils40.formatEtherNum)(
60905
+ const totalRewardsReceived = (0, import_utils43.formatEtherNum)(
60632
60906
  tokeRewards.rewardsPayload.payload.amount || 0n
60633
60907
  );
60634
60908
  const totalRewardsReceivedUsd = tokePrice * totalRewardsReceived;
@@ -60645,11 +60919,11 @@ var getChainUserSTokeRewards = async (wagmiConfig, {
60645
60919
  };
60646
60920
 
60647
60921
  // functions/getChainSubgraphStatus.ts
60648
- var import_graph_cli15 = require("@tokemak/graph-cli");
60922
+ var import_graph_cli16 = require("@tokemak/graph-cli");
60649
60923
  var getChainSubgraphStatus = async (chain) => {
60650
60924
  const currentTimestamp = Math.floor(Date.now() / 1e3);
60651
60925
  try {
60652
- const { GetLatestSubgraphTimestamp } = (0, import_graph_cli15.getSdkByChainId)(
60926
+ const { GetLatestSubgraphTimestamp } = (0, import_graph_cli16.getSdkByChainId)(
60653
60927
  chain.chainId
60654
60928
  );
60655
60929
  const { _meta } = await GetLatestSubgraphTimestamp();
@@ -60703,13 +60977,13 @@ var getSubgraphStatus = async (includeTestnet = false) => {
60703
60977
  // functions/getCycleV1.ts
60704
60978
  var import_core21 = require("@wagmi/core");
60705
60979
  var import_abis20 = require("@tokemak/abis");
60706
- var import_viem19 = require("viem");
60707
- var import_utils42 = require("@tokemak/utils");
60980
+ var import_viem20 = require("viem");
60981
+ var import_utils45 = require("@tokemak/utils");
60708
60982
  var import_config18 = require("@tokemak/config");
60709
60983
  var import_chains10 = require("viem/chains");
60710
- var publicClient = (0, import_viem19.createPublicClient)({
60984
+ var publicClient = (0, import_viem20.createPublicClient)({
60711
60985
  chain: import_chains10.mainnet,
60712
- transport: (0, import_viem19.http)("https://mainnet.infura.io/v3/2BtQ5D1QEPHvwgZwKwnZC7WQVhr")
60986
+ transport: (0, import_viem20.http)("https://mainnet.infura.io/v3/2BtQ5D1QEPHvwgZwKwnZC7WQVhr")
60713
60987
  });
60714
60988
  var getCycleV1 = async (wagmiConfig, {
60715
60989
  currentBlockNumber,
@@ -60738,11 +61012,11 @@ var getCycleV1 = async (wagmiConfig, {
60738
61012
  });
60739
61013
  const rolloverEvents = await publicClient.getFilterLogs({ filter });
60740
61014
  const cycleRolloverBlockNumber = chainId === 1 ? rolloverEvents[rolloverEvents.length - 1]?.blockNumber : rolloverEvents[rolloverEvents.length - 1]?.blockNumber || currentBlockNumber;
60741
- const secondsLeftBeforeNextCycle = (0, import_utils42.convertChainCycleToUnix)(Number(currentCycleIndex) + 1) - Date.now() / 1e3;
61015
+ const secondsLeftBeforeNextCycle = (0, import_utils45.convertChainCycleToUnix)(Number(currentCycleIndex) + 1) - Date.now() / 1e3;
60742
61016
  return {
60743
61017
  currentCycleIndex,
60744
61018
  cycleRolloverBlockNumber,
60745
- timeBeforeNextCycle: (0, import_utils42.convertSecondsToRemainingTime)(
61019
+ timeBeforeNextCycle: (0, import_utils45.convertSecondsToRemainingTime)(
60746
61020
  secondsLeftBeforeNextCycle
60747
61021
  )
60748
61022
  };
@@ -60753,7 +61027,7 @@ var getCycleV1 = async (wagmiConfig, {
60753
61027
  };
60754
61028
 
60755
61029
  // functions/getProtocolStats.ts
60756
- var import_utils43 = require("@tokemak/utils");
61030
+ var import_utils46 = require("@tokemak/utils");
60757
61031
  var getProtocolStats = async (autopools, stoke, sushiLP) => {
60758
61032
  try {
60759
61033
  if (!autopools || !stoke || !sushiLP) {
@@ -60783,12 +61057,12 @@ var getProtocolStats = async (autopools, stoke, sushiLP) => {
60783
61057
  Object.entries(categories).map(([key, value]) => [
60784
61058
  key,
60785
61059
  {
60786
- tvl: (0, import_utils43.formatTVL)(value.tvl),
60787
- supply: (0, import_utils43.formatLargeNumber)(value.supply || 0)
61060
+ tvl: (0, import_utils46.formatTVL)(value.tvl),
61061
+ supply: (0, import_utils46.formatLargeNumber)(value.supply || 0)
60788
61062
  }
60789
61063
  ])
60790
61064
  );
60791
- const tvl = (0, import_utils43.formatTVL)(autopoolTVL + stoke.rawTVL + (sushiLP?.tvl || 0));
61065
+ const tvl = (0, import_utils46.formatTVL)(autopoolTVL + stoke.rawTVL + (sushiLP?.tvl || 0));
60792
61066
  const vaultAddresses = autopools?.flatMap(
60793
61067
  (pool) => pool.destinations.map((destination) => destination.vaultAddress)
60794
61068
  );
@@ -60796,16 +61070,16 @@ var getProtocolStats = async (autopools, stoke, sushiLP) => {
60796
61070
  const totalDestinations = uniqueVaultAddresses.length;
60797
61071
  return {
60798
61072
  autopools: {
60799
- tvl: (0, import_utils43.formatTVL)(autopoolTVL),
61073
+ tvl: (0, import_utils46.formatTVL)(autopoolTVL),
60800
61074
  tvlNum: autopoolTVL,
60801
61075
  categories: formattedCategories
60802
61076
  },
60803
61077
  stoke: {
60804
- tvl: (0, import_utils43.formatTVL)(stoke.rawTVL),
61078
+ tvl: (0, import_utils46.formatTVL)(stoke.rawTVL),
60805
61079
  totalSupply: `${stoke.totalSupply} TOKE`
60806
61080
  },
60807
61081
  sushiLP: {
60808
- tvl: (0, import_utils43.formatTVL)(sushiLP?.tvl || 0),
61082
+ tvl: (0, import_utils46.formatTVL)(sushiLP?.tvl || 0),
60809
61083
  totalSupply: sushiLP?.totalSupply || 0
60810
61084
  },
60811
61085
  tvl,
@@ -60818,18 +61092,18 @@ var getProtocolStats = async (autopools, stoke, sushiLP) => {
60818
61092
  };
60819
61093
 
60820
61094
  // functions/getRebalanceStats.ts
60821
- var import_graph_cli16 = require("@tokemak/graph-cli");
61095
+ var import_graph_cli17 = require("@tokemak/graph-cli");
60822
61096
 
60823
61097
  // functions/getEthPriceAtBlock.ts
60824
61098
  var import_getCoreConfig = require("@tokemak/config/helpers/getCoreConfig");
60825
61099
  var import_core22 = require("@wagmi/core");
60826
61100
  var import_abis21 = require("@tokemak/abis");
60827
- var import_tokenlist10 = require("@tokemak/tokenlist");
61101
+ var import_tokenlist11 = require("@tokemak/tokenlist");
60828
61102
  var getEthPriceAtBlock = async (wagmiConfig, blockNumber, chainId) => {
60829
61103
  const config = (0, import_getCoreConfig.getCoreConfig)(chainId);
60830
61104
  const rootPriceOracle = config.rootPriceOracle;
60831
61105
  const weth = config.weth;
60832
- const usdc = import_tokenlist10.USDC_TOKEN.extensions?.bridgeInfo?.[chainId]?.tokenAddress || import_tokenlist10.USDC_TOKEN.address;
61106
+ const usdc = import_tokenlist11.USDC_TOKEN.extensions?.bridgeInfo?.[chainId]?.tokenAddress || import_tokenlist11.USDC_TOKEN.address;
60833
61107
  const priceAtBlock = await (0, import_core22.readContract)(wagmiConfig, {
60834
61108
  address: rootPriceOracle,
60835
61109
  abi: import_abis21.rootPriceOracleAbi,
@@ -60842,59 +61116,76 @@ var getEthPriceAtBlock = async (wagmiConfig, blockNumber, chainId) => {
60842
61116
  };
60843
61117
 
60844
61118
  // functions/getRebalanceStats.ts
60845
- var import_utils45 = require("@tokemak/utils");
60846
- var import_tokenlist11 = require("@tokemak/tokenlist");
61119
+ var import_utils48 = require("@tokemak/utils");
61120
+ var import_tokenlist12 = require("@tokemak/tokenlist");
60847
61121
  var import_chains11 = require("viem/chains");
60848
61122
  var BATCH_SIZE = 500;
60849
61123
  var fetchChainRebalances = async (chainId) => {
60850
- const { GetAllAutopoolRebalances } = (0, import_graph_cli16.getSdkByChainId)(chainId);
61124
+ const { GetAllAutopoolRebalances } = (0, import_graph_cli17.getSdkByChainId)(chainId);
60851
61125
  const allRebalances = await paginateQuery(
60852
61126
  GetAllAutopoolRebalances,
60853
61127
  "autopoolRebalances"
60854
61128
  );
60855
61129
  if (allRebalances.length === 0) {
60856
- throw new Error("Could not fetch rebalance values");
61130
+ return [];
60857
61131
  }
60858
61132
  return allRebalances;
60859
61133
  };
60860
- var processRebalance = async (rebalance, chainId, wagmiConfig) => {
61134
+ function inferBaseAssetDecimals(rebalance, chainId) {
61135
+ if (BigInt(rebalance.tokenOutValueBaseAsset) === BigInt(rebalance.tokenOutValueInEth)) {
61136
+ return 18;
61137
+ }
61138
+ if (chainId === import_chains11.sonic.id) {
61139
+ return rebalance.tokenOut.decimals;
61140
+ }
61141
+ return import_tokenlist12.USDC_TOKEN.decimals;
61142
+ }
61143
+ var getRebalanceValueUsd = async (rebalance, chainId, wagmiConfig) => {
61144
+ const ethWei = BigInt(rebalance.tokenOutValueInEth || "0");
61145
+ if (ethWei === 0n)
61146
+ return null;
60861
61147
  try {
60862
- let valueInUsd = 0;
60863
- if (chainId === import_chains11.sonic.id) {
60864
- console.log(rebalance.tokenOutValueBaseAsset);
60865
- const tokenOutValueInBaseAsset = (0, import_utils45.formatUnitsNum)(
60866
- BigInt(rebalance.tokenOutValueBaseAsset),
60867
- import_tokenlist11.USDC_TOKEN.decimals
60868
- );
60869
- valueInUsd = tokenOutValueInBaseAsset;
60870
- } else {
60871
- const blockNumber = BigInt(rebalance.blockNumber);
60872
- const price = await getEthPriceAtBlock(
60873
- wagmiConfig,
60874
- blockNumber,
60875
- chainId
60876
- );
60877
- const tokenOutValueInEth = (0, import_utils45.formatEtherNum)(
60878
- BigInt(rebalance.tokenOutValueInEth)
60879
- );
60880
- let formattedPrice = (0, import_utils45.formatUnitsNum)(price, import_tokenlist11.USDC_TOKEN.decimals);
60881
- valueInUsd = tokenOutValueInEth * formattedPrice;
60882
- }
60883
- return {
60884
- timestamp: rebalance.timestamp,
60885
- blockNumber: rebalance.blockNumber,
60886
- chainId,
60887
- valueInUsd
60888
- };
61148
+ const price = await getEthPriceAtBlock(
61149
+ wagmiConfig,
61150
+ BigInt(rebalance.blockNumber),
61151
+ chainId
61152
+ );
61153
+ const ethUsd = Number((0, import_utils48.formatUnitsNum)(price, import_tokenlist12.USDC_TOKEN.decimals));
61154
+ const ethAmt = Number((0, import_utils48.formatEtherNum)(ethWei));
61155
+ const usd = ethAmt * ethUsd;
61156
+ return usd;
60889
61157
  } catch (e) {
60890
- console.log(e);
61158
+ console.warn(`WETH/USDC oracle unavailable for chainId: ${chainId}`);
61159
+ return null;
61160
+ }
61161
+ };
61162
+ var processRebalance = async (rebalance, chainId, wagmiConfig) => {
61163
+ const ethPathUsd = await getRebalanceValueUsd(
61164
+ rebalance,
61165
+ chainId,
61166
+ wagmiConfig
61167
+ );
61168
+ if (ethPathUsd != null) {
60891
61169
  return {
60892
61170
  timestamp: rebalance.timestamp,
60893
61171
  blockNumber: rebalance.blockNumber,
60894
61172
  chainId,
60895
- valueInUsd: 0
61173
+ valueInUsd: ethPathUsd
60896
61174
  };
60897
61175
  }
61176
+ const baseDecimals = inferBaseAssetDecimals(rebalance, chainId);
61177
+ const baseUsd = Number(
61178
+ (0, import_utils48.formatUnitsNum)(
61179
+ BigInt(rebalance.tokenOutValueBaseAsset || "0"),
61180
+ baseDecimals
61181
+ )
61182
+ );
61183
+ return {
61184
+ timestamp: rebalance.timestamp,
61185
+ blockNumber: rebalance.blockNumber,
61186
+ chainId,
61187
+ valueInUsd: baseUsd
61188
+ };
60898
61189
  };
60899
61190
  var processRebalancesInBatches = async (rebalances, chainId, wagmiConfig) => {
60900
61191
  const processedRebalances = [];
@@ -60978,6 +61269,7 @@ var updateRebalanceStats = async (wagmiConfig, {
60978
61269
  BASE_ASSETS,
60979
61270
  BATCH_SIZE,
60980
61271
  ETH_BASE_ASSETS,
61272
+ EUR_BASE_ASSETS,
60981
61273
  MessageStatus,
60982
61274
  PRICED_TOKENS,
60983
61275
  USD_BASE_ASSETS,
@@ -61032,6 +61324,7 @@ var updateRebalanceStats = async (wagmiConfig, {
61032
61324
  getPoolsAndDestinations,
61033
61325
  getProtocolStats,
61034
61326
  getRebalanceStats,
61327
+ getRebalanceValueUsd,
61035
61328
  getRewardsPayloadV1,
61036
61329
  getSToke,
61037
61330
  getSTokeChainsForEnv,