@pyxisjs/chains 0.2.7 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -305,84 +305,6 @@ var require_dayjs_min = __commonJS({
305
305
  }
306
306
  });
307
307
 
308
- // ../../node_modules/.pnpm/dayjs@1.11.19/node_modules/dayjs/plugin/utc.js
309
- var require_utc = __commonJS({
310
- "../../node_modules/.pnpm/dayjs@1.11.19/node_modules/dayjs/plugin/utc.js"(exports, module) {
311
- "use strict";
312
- !(function(t, i) {
313
- "object" == typeof exports && "undefined" != typeof module ? module.exports = i() : "function" == typeof define && define.amd ? define(i) : (t = "undefined" != typeof globalThis ? globalThis : t || self).dayjs_plugin_utc = i();
314
- })(exports, (function() {
315
- "use strict";
316
- var t = "minute", i = /[+-]\d\d(?::?\d\d)?/g, e = /([+-]|\d\d)/g;
317
- return function(s, f, n) {
318
- var u = f.prototype;
319
- n.utc = function(t2) {
320
- var i2 = { date: t2, utc: true, args: arguments };
321
- return new f(i2);
322
- }, u.utc = function(i2) {
323
- var e2 = n(this.toDate(), { locale: this.$L, utc: true });
324
- return i2 ? e2.add(this.utcOffset(), t) : e2;
325
- }, u.local = function() {
326
- return n(this.toDate(), { locale: this.$L, utc: false });
327
- };
328
- var r = u.parse;
329
- u.parse = function(t2) {
330
- t2.utc && (this.$u = true), this.$utils().u(t2.$offset) || (this.$offset = t2.$offset), r.call(this, t2);
331
- };
332
- var o = u.init;
333
- u.init = function() {
334
- if (this.$u) {
335
- var t2 = this.$d;
336
- this.$y = t2.getUTCFullYear(), this.$M = t2.getUTCMonth(), this.$D = t2.getUTCDate(), this.$W = t2.getUTCDay(), this.$H = t2.getUTCHours(), this.$m = t2.getUTCMinutes(), this.$s = t2.getUTCSeconds(), this.$ms = t2.getUTCMilliseconds();
337
- } else o.call(this);
338
- };
339
- var a = u.utcOffset;
340
- u.utcOffset = function(s2, f2) {
341
- var n2 = this.$utils().u;
342
- if (n2(s2)) return this.$u ? 0 : n2(this.$offset) ? a.call(this) : this.$offset;
343
- if ("string" == typeof s2 && (s2 = (function(t2) {
344
- void 0 === t2 && (t2 = "");
345
- var s3 = t2.match(i);
346
- if (!s3) return null;
347
- var f3 = ("" + s3[0]).match(e) || ["-", 0, 0], n3 = f3[0], u3 = 60 * +f3[1] + +f3[2];
348
- return 0 === u3 ? 0 : "+" === n3 ? u3 : -u3;
349
- })(s2), null === s2)) return this;
350
- var u2 = Math.abs(s2) <= 16 ? 60 * s2 : s2;
351
- if (0 === u2) return this.utc(f2);
352
- var r2 = this.clone();
353
- if (f2) return r2.$offset = u2, r2.$u = false, r2;
354
- var o2 = this.$u ? this.toDate().getTimezoneOffset() : -1 * this.utcOffset();
355
- return (r2 = this.local().add(u2 + o2, t)).$offset = u2, r2.$x.$localOffset = o2, r2;
356
- };
357
- var h = u.format;
358
- u.format = function(t2) {
359
- var i2 = t2 || (this.$u ? "YYYY-MM-DDTHH:mm:ss[Z]" : "");
360
- return h.call(this, i2);
361
- }, u.valueOf = function() {
362
- var t2 = this.$utils().u(this.$offset) ? 0 : this.$offset + (this.$x.$localOffset || this.$d.getTimezoneOffset());
363
- return this.$d.valueOf() - 6e4 * t2;
364
- }, u.isUTC = function() {
365
- return !!this.$u;
366
- }, u.toISOString = function() {
367
- return this.toDate().toISOString();
368
- }, u.toString = function() {
369
- return this.toDate().toUTCString();
370
- };
371
- var l = u.toDate;
372
- u.toDate = function(t2) {
373
- return "s" === t2 && this.$offset ? n(this.format("YYYY-MM-DD HH:mm:ss:SSS")).toDate() : l.call(this);
374
- };
375
- var c = u.diff;
376
- u.diff = function(t2, i2, e2) {
377
- if (t2 && this.$u === t2.$u) return c.call(this, t2, i2, e2);
378
- var s2 = this.local(), f2 = n(t2).local();
379
- return c.call(s2, f2, i2, e2);
380
- };
381
- };
382
- }));
383
- }
384
- });
385
-
386
308
  // src/aptos/abis/Accountant.json
387
309
  var Accountant_default = {
388
310
  address: "0x6b678b5d9925d82c6fdbbbb6d379da750198cd78c078759047c9494d57c2873e",
@@ -8743,304 +8665,15 @@ var AptosChainAdapter = class extends BaseChainAdapter {
8743
8665
  }
8744
8666
  };
8745
8667
 
8746
- // src/aptos/analytics-client.ts
8747
- var import_dayjs = __toESM(require_dayjs_min());
8748
- var import_utc = __toESM(require_utc());
8749
- import {
8750
- ChainType as ChainType2,
8751
- getChainConfig as getChainConfig2,
8752
- PyxisUtils as PyxisUtils2
8753
- } from "@pyxisjs/core";
8754
-
8755
- // src/aptos/analytics-utils.ts
8756
- var apyWindowDaysMap = {
8757
- "7d": 7,
8758
- "30d": 30,
8759
- alltime: 0
8760
- };
8761
- var buildActivitiesQuery = (vault, user, offset, pageSize) => {
8762
- const variables = {
8763
- offset,
8764
- limit: pageSize
8765
- };
8766
- const variableDefinitions = ["$offset: Int!", "$limit: Int!"];
8767
- const whereConditions = [];
8768
- if (vault) {
8769
- variables.vault = vault;
8770
- variableDefinitions.push("$vault: String");
8771
- whereConditions.push("{vault: { _eq: $vault }}");
8772
- }
8773
- if (user) {
8774
- variables.user = user;
8775
- variableDefinitions.push("$user: String");
8776
- whereConditions.push("{user: { _eq: $user }}");
8777
- }
8778
- if (whereConditions.length === 0) {
8779
- throw new Error("At least one of vault or user must be provided");
8780
- }
8781
- const whereClause = whereConditions.length > 1 ? `_and: [${whereConditions.join(", ")}]` : whereConditions[0].slice(1, -1);
8782
- const query = `
8783
- query ActivityQuery(${variableDefinitions.join(", ")}) {
8784
- activities(where: {
8785
- ${whereClause}
8786
- },
8787
- order_by: {tx_version: desc},
8788
- offset: $offset,
8789
- limit: $limit) {
8790
- deposit_amount
8791
- deposit_token
8792
- event_type
8793
- tx_hash
8794
- tx_version
8795
- tx_timestamp
8796
- user
8797
- vault
8798
- withdraw_amount
8799
- withdraw_token
8800
- }
8801
- activities_aggregate(where: {
8802
- ${whereClause}
8803
- },) {
8804
- aggregate {
8805
- count
8806
- }
8807
- }
8808
- }
8809
- `;
8810
- return { query, variables };
8811
- };
8812
- var buildExchangeRateEventsQuery = (vault, startTime, endTime) => {
8813
- const query = `
8814
- query ExchangeRates($vault: String!, $startTime: numeric!, $endTime: numeric!) {
8815
- exchange_rate_updated_events(where: {current_time: {_lte: $endTime, _gte: $startTime}, vault: {_eq: $vault}}, order_by: {current_time: asc}) {
8816
- current_time
8817
- new_deposit_rate
8818
- new_withdraw_rate
8819
- old_deposit_rate
8820
- old_withdraw_rate
8821
- vault
8822
- type
8823
- }
8824
- }
8825
- `;
8826
- return {
8827
- query,
8828
- variables: {
8829
- vault,
8830
- startTime,
8831
- endTime
8832
- }
8833
- };
8834
- };
8835
- function mapIndexerToVaultActivity(indexerActivity) {
8836
- return {
8837
- depositAmount: indexerActivity.deposit_amount,
8838
- depositToken: indexerActivity.deposit_token,
8839
- eventType: indexerActivity.event_type,
8840
- txHash: indexerActivity.tx_hash,
8841
- txVersion: indexerActivity.tx_version,
8842
- txTimestamp: indexerActivity.tx_timestamp,
8843
- user: indexerActivity.user,
8844
- vault: indexerActivity.vault,
8845
- withdrawAmount: indexerActivity.withdraw_amount,
8846
- withdrawToken: indexerActivity.withdraw_token
8847
- };
8848
- }
8849
- function getFunctionSignature2(contractName, functionName, contractAddress) {
8850
- const signatures = {
8851
- accountant: {
8852
- calculate_shares_from_assets_safe: "{address}::accountant::calculate_shares_from_assets_safe",
8853
- calculate_assets_from_shares_safe: "{address}::accountant::calculate_assets_from_shares_safe",
8854
- get_withdraw_rate_in_quote_safe: "{address}::accountant::get_withdraw_rate_in_quote_safe",
8855
- get_deposit_rate_in_quote_safe: "{address}::accountant::get_deposit_rate_in_quote_safe"
8856
- },
8857
- teller: {
8858
- deposit: "{address}::teller::deposit"
8859
- },
8860
- atomicQueue: {
8861
- get_minimum_request_age: "{address}::atomic_queue::get_minimum_request_age"
8862
- }
8863
- };
8864
- const contractSignatures = signatures[contractName];
8865
- if (!contractSignatures) {
8866
- throw new Error(`Contract ${contractName} not found`);
8867
- }
8868
- const signature = contractSignatures[functionName];
8869
- if (!signature) {
8870
- throw new Error(
8871
- `Function ${functionName} not found in contract ${contractName}`
8872
- );
8873
- }
8874
- return signature.replace("{address}", contractAddress);
8875
- }
8876
-
8877
- // src/aptos/analytics-client.ts
8878
- import_dayjs.default.extend(import_utc.default);
8879
- var MIN_APY_DATA_POINTS = 2;
8880
- var DEFAULT_PAGE_SIZE = 10;
8881
- var DEFAULT_APY_WINDOW_DAYS = 7;
8882
- var THIRTY_DAYS = 30;
8883
- var AptosAnalyticsClient = class {
8884
- constructor(chainAdapter, analyticsAdapter) {
8885
- this.chainAdapter = chainAdapter;
8886
- this.analyticsAdapter = analyticsAdapter;
8887
- const config = getChainConfig2(chainAdapter.chain.id);
8888
- invariant(
8889
- config.type === ChainType2.MoveVM,
8890
- "AptosAnalyticsClient requires a MoveVM chain adapter"
8891
- );
8892
- }
8893
- /**
8894
- * Get function signature using contract address from adapter
8895
- */
8896
- getBaseFunctionSignature(contractName, functionName) {
8897
- const contractAddress = this.chainAdapter.getContractAddress(contractName);
8898
- return getFunctionSignature2(contractName, functionName, contractAddress);
8899
- }
8900
- async getActivities({
8901
- vault,
8902
- user,
8903
- page = 1,
8904
- pageSize = DEFAULT_PAGE_SIZE
8905
- }) {
8906
- const offset = (page - 1) * pageSize;
8907
- const { query, variables } = buildActivitiesQuery(
8908
- vault,
8909
- user,
8910
- offset,
8911
- pageSize
8912
- );
8913
- const response = await this.analyticsAdapter.queryIndexer({
8914
- query,
8915
- variables
8916
- });
8917
- const activities = response.activities.map(mapIndexerToVaultActivity);
8918
- return {
8919
- activities,
8920
- total: response.activities_aggregate.aggregate.count
8921
- };
8922
- }
8923
- async getTvlInBaseAsset({ vault, asset }) {
8924
- const normalizedVault = PyxisUtils2.normalizeAddress(vault);
8925
- const normalizedAsset = PyxisUtils2.normalizeAddress(asset);
8926
- const {
8927
- vec: [balance]
8928
- } = await this.chainAdapter.viewContract({
8929
- function: "0x1::fungible_asset::supply",
8930
- typeArguments: ["0x1::fungible_asset::Metadata"],
8931
- arguments: [normalizedVault]
8932
- });
8933
- const functionSignature = this.getBaseFunctionSignature(
8934
- "accountant",
8935
- "calculate_assets_from_shares_safe"
8936
- );
8937
- const baseAssetAmount = await this.chainAdapter.viewContract({
8938
- function: functionSignature,
8939
- arguments: [normalizedVault, normalizedAsset, balance]
8940
- });
8941
- return baseAssetAmount;
8942
- }
8943
- async getUpdateExchangeRateEvents({
8944
- vault,
8945
- startTime,
8946
- endTime
8947
- }) {
8948
- const { query, variables } = buildExchangeRateEventsQuery(
8949
- vault,
8950
- startTime,
8951
- endTime
8952
- );
8953
- const response = await this.analyticsAdapter.queryIndexer({
8954
- query,
8955
- variables
8956
- });
8957
- return response.exchange_rate_updated_events.map(
8958
- PyxisUtils2.mapIndexerToExchangeRateEvent
8959
- );
8960
- }
8961
- async get30DayApy(vault) {
8962
- const startTime = (0, import_dayjs.default)().utc().subtract(THIRTY_DAYS, "day").startOf("day").unix();
8963
- const endTime = (0, import_dayjs.default)().utc().endOf("day").unix();
8964
- const vaultExchangeRateUpdateEvents = await this.getUpdateExchangeRateEvents({
8965
- vault,
8966
- startTime,
8967
- endTime
8968
- });
8969
- if (vaultExchangeRateUpdateEvents.length < MIN_APY_DATA_POINTS) {
8970
- return "0";
8971
- }
8972
- vaultExchangeRateUpdateEvents.sort(
8973
- (a, b) => Number(a.timestamp) - Number(b.timestamp)
8974
- );
8975
- return PyxisUtils2.calculateApy(
8976
- vaultExchangeRateUpdateEvents[0],
8977
- vaultExchangeRateUpdateEvents[vaultExchangeRateUpdateEvents.length - 1]
8978
- );
8979
- }
8980
- async getHistoricalApy({
8981
- vault,
8982
- startTime,
8983
- endTime,
8984
- window = "alltime"
8985
- }) {
8986
- const historicalExchangeRateEvents = await this.getUpdateExchangeRateEvents(
8987
- {
8988
- vault,
8989
- startTime,
8990
- endTime
8991
- }
8992
- );
8993
- if (historicalExchangeRateEvents.length < MIN_APY_DATA_POINTS) {
8994
- return [];
8995
- }
8996
- historicalExchangeRateEvents.sort(
8997
- (a, b) => Number(a.timestamp) - Number(b.timestamp)
8998
- );
8999
- const sampledEvents = PyxisUtils2.sampleEventsByDay(
9000
- historicalExchangeRateEvents
9001
- );
9002
- if (sampledEvents.length < MIN_APY_DATA_POINTS) {
9003
- return [];
9004
- }
9005
- const historicalApyData = sampledEvents.map((event, i) => {
9006
- if (i === 0) return null;
9007
- let baseEventIndex = 0;
9008
- if (window === "alltime") {
9009
- baseEventIndex = 0;
9010
- } else {
9011
- const daysToSubtract = apyWindowDaysMap[window] ?? DEFAULT_APY_WINDOW_DAYS;
9012
- const firstEventTime = import_dayjs.default.unix(Number(sampledEvents[0].timestamp));
9013
- const currentEventTime = import_dayjs.default.unix(Number(event.timestamp));
9014
- if (currentEventTime.diff(firstEventTime, "day") < daysToSubtract) {
9015
- return null;
9016
- }
9017
- const pastTime = currentEventTime.subtract(daysToSubtract, "day");
9018
- for (let j = i - 1; j >= 0; j--) {
9019
- const eventTime = import_dayjs.default.unix(Number(sampledEvents[j].timestamp));
9020
- if (eventTime.isSame(pastTime, "date")) {
9021
- baseEventIndex = j;
9022
- break;
9023
- }
9024
- }
9025
- }
9026
- return {
9027
- value: PyxisUtils2.calculateApy(sampledEvents[baseEventIndex], event),
9028
- timestamp: event.timestamp
9029
- };
9030
- }).filter((item) => item !== null);
9031
- return historicalApyData;
9032
- }
9033
- };
9034
-
9035
8668
  // src/evm/adapter.ts
9036
- var import_dayjs2 = __toESM(require_dayjs_min());
8669
+ var import_dayjs = __toESM(require_dayjs_min());
9037
8670
  import { Options as Options2 } from "@layerzerolabs/lz-v2-utilities";
9038
8671
  import {
9039
- BaseChainAdapter as BaseChainAdapter3,
8672
+ BaseChainAdapter as BaseChainAdapter2,
9040
8673
  BridgeMethod as BridgeMethod2,
9041
8674
  ChainId,
9042
- PyxisUtils as PyxisUtils3,
9043
- getChainConfig as getChainConfig3,
8675
+ PyxisUtils as PyxisUtils2,
8676
+ getChainConfig as getChainConfig2,
9044
8677
  getEstimatedBridgeTime as getEstimatedBridgeTime2,
9045
8678
  getLayerZeroEndpointId as getLayerZeroEndpointId2,
9046
8679
  getLayerZeroGasLimit
@@ -9058,7 +8691,7 @@ var viemChainMap = {
9058
8691
  [ChainId.ETHEREUM_SEPOLIA]: sepolia,
9059
8692
  [ChainId.ARBITRUM_ONE]: arbitrum
9060
8693
  };
9061
- var EthereumChainAdapter = class extends BaseChainAdapter3 {
8694
+ var EthereumChainAdapter = class extends BaseChainAdapter2 {
9062
8695
  constructor(chain) {
9063
8696
  super(chain);
9064
8697
  this.viemChain = viemChainMap[chain.id];
@@ -9086,7 +8719,7 @@ var EthereumChainAdapter = class extends BaseChainAdapter3 {
9086
8719
  * Build an Ethereum transaction payload
9087
8720
  */
9088
8721
  async buildPayload(params) {
9089
- const config = getChainConfig3(this.chain.id);
8722
+ const config = getChainConfig2(this.chain.id);
9090
8723
  if (!config.chainId) {
9091
8724
  throw new Error("Chain ID is required for EVM transactions");
9092
8725
  }
@@ -9212,7 +8845,7 @@ var EthereumChainAdapter = class extends BaseChainAdapter3 {
9212
8845
  * Get function signature using the new configuration system
9213
8846
  */
9214
8847
  getFunctionSignature(contractName, functionName) {
9215
- const config = getChainConfig3(this.chain.id);
8848
+ const config = getChainConfig2(this.chain.id);
9216
8849
  const contractAddress = this.getContractAddress(contractName);
9217
8850
  return getFunctionSignature(
9218
8851
  config.type,
@@ -9225,7 +8858,7 @@ var EthereumChainAdapter = class extends BaseChainAdapter3 {
9225
8858
  * Get contract ABI using the new configuration system
9226
8859
  */
9227
8860
  getContractABI(contractName) {
9228
- const config = getChainConfig3(this.chain.id);
8861
+ const config = getChainConfig2(this.chain.id);
9229
8862
  return getContractABI(config.type, contractName);
9230
8863
  }
9231
8864
  async getWithdrawRateInQuoteSafe(args) {
@@ -9297,7 +8930,7 @@ var EthereumChainAdapter = class extends BaseChainAdapter3 {
9297
8930
  "multiChainLzTeller contract address not configured."
9298
8931
  );
9299
8932
  const dstEid = getLayerZeroEndpointId2(destinationChain);
9300
- const config = getChainConfig3(this.chain.id);
8933
+ const config = getChainConfig2(this.chain.id);
9301
8934
  const functionSignature = getFunctionSignature(
9302
8935
  config.type,
9303
8936
  "multiChainLzTeller",
@@ -9337,7 +8970,7 @@ var EthereumChainAdapter = class extends BaseChainAdapter3 {
9337
8970
  lzTellerAddress,
9338
8971
  "Vault does not support bridging. multiChainLzTeller contract address not configured."
9339
8972
  );
9340
- const config = getChainConfig3(this.chain.id);
8973
+ const config = getChainConfig2(this.chain.id);
9341
8974
  const functionSignature = getFunctionSignature(
9342
8975
  config.type,
9343
8976
  "multiChainLzTeller",
@@ -9407,7 +9040,7 @@ var EthereumChainAdapter = class extends BaseChainAdapter3 {
9407
9040
  Number(args.offerAmount),
9408
9041
  false,
9409
9042
  // inSolve: Default false
9410
- (0, import_dayjs2.default)().unix()
9043
+ (0, import_dayjs.default)().unix()
9411
9044
  // UpdatedAt: current unix timestamp
9412
9045
  ]
9413
9046
  ],
@@ -9458,7 +9091,7 @@ var EthereumChainAdapter = class extends BaseChainAdapter3 {
9458
9091
  flag,
9459
9092
  matchAll
9460
9093
  }) {
9461
- const requestFlag = PyxisUtils3.buildRequestFlags(flag);
9094
+ const requestFlag = PyxisUtils2.buildRequestFlags(flag);
9462
9095
  const getAllWithdrawalRequestFn = this.getFunctionSignature(
9463
9096
  "atomicQueue",
9464
9097
  "get_all_atomic_requests"
@@ -9485,7 +9118,7 @@ var EthereumChainAdapter = class extends BaseChainAdapter3 {
9485
9118
  return {
9486
9119
  atomicPrice: request.atomicPrice,
9487
9120
  deadline: request.deadline,
9488
- flags: PyxisUtils3.parseRequestFlags(solveData.flags),
9121
+ flags: PyxisUtils2.parseRequestFlags(solveData.flags),
9489
9122
  offerAmount: request.offerAmount,
9490
9123
  offerToken: request.offerToken,
9491
9124
  userAddress: request.user,
@@ -9518,7 +9151,6 @@ var EthereumChainAdapter = class extends BaseChainAdapter3 {
9518
9151
  export {
9519
9152
  AccountantABI,
9520
9153
  AccountantAptosABI,
9521
- AptosAnalyticsClient,
9522
9154
  AptosChainAdapter,
9523
9155
  AtomicQueueABI,
9524
9156
  AtomicQueueAptosABI,
@@ -9530,7 +9162,6 @@ export {
9530
9162
  TellerWithMultiAssetSupportABI,
9531
9163
  VaultAptosABI,
9532
9164
  getContractABI,
9533
- getFunctionSignature,
9534
- mapIndexerToVaultActivity
9165
+ getFunctionSignature
9535
9166
  };
9536
9167
  //# sourceMappingURL=index.mjs.map