@pyxisjs/chains 0.3.0 → 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,341 +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/common/stats-client.ts
8878
- var PyxisStatsClient = class {
8879
- constructor(baseUrl = "https://stats.pyxisfinance.xyz/v1") {
8880
- this.baseUrl = baseUrl;
8881
- }
8882
- async getManageOperations({
8883
- vaultId,
8884
- startTime,
8885
- endTime,
8886
- limit = 100
8887
- }) {
8888
- const params = new URLSearchParams({
8889
- start_time: startTime.toString(),
8890
- end_time: endTime.toString(),
8891
- limit: limit.toString()
8892
- });
8893
- const url = `${this.baseUrl}/vaults/${vaultId}/manage-operations?${params}`;
8894
- const response = await fetch(url);
8895
- if (!response.ok) {
8896
- throw new Error(
8897
- `Failed to fetch manage operations: ${response.status} ${response.statusText}`
8898
- );
8899
- }
8900
- const data = await response.json();
8901
- if (data.code !== 0) {
8902
- throw new Error(
8903
- `Manage operations API error: ${data.message} (code: ${data.code})`
8904
- );
8905
- }
8906
- return data.data.items;
8907
- }
8908
- };
8909
-
8910
- // src/aptos/analytics-client.ts
8911
- import_dayjs.default.extend(import_utc.default);
8912
- var MIN_APY_DATA_POINTS = 2;
8913
- var DEFAULT_PAGE_SIZE = 10;
8914
- var DEFAULT_APY_WINDOW_DAYS = 7;
8915
- var THIRTY_DAYS = 30;
8916
- var AptosAnalyticsClient = class {
8917
- constructor(chainAdapter, analyticsAdapter) {
8918
- this.chainAdapter = chainAdapter;
8919
- this.analyticsAdapter = analyticsAdapter;
8920
- this.statsClient = new PyxisStatsClient();
8921
- const config = getChainConfig2(chainAdapter.chain.id);
8922
- invariant(
8923
- config.type === ChainType2.MoveVM,
8924
- "AptosAnalyticsClient requires a MoveVM chain adapter"
8925
- );
8926
- }
8927
- /**
8928
- * Get function signature using contract address from adapter
8929
- */
8930
- getBaseFunctionSignature(contractName, functionName) {
8931
- const contractAddress = this.chainAdapter.getContractAddress(contractName);
8932
- return getFunctionSignature2(contractName, functionName, contractAddress);
8933
- }
8934
- async getActivities({
8935
- vault,
8936
- user,
8937
- page = 1,
8938
- pageSize = DEFAULT_PAGE_SIZE
8939
- }) {
8940
- const offset = (page - 1) * pageSize;
8941
- const { query, variables } = buildActivitiesQuery(
8942
- vault,
8943
- user,
8944
- offset,
8945
- pageSize
8946
- );
8947
- const response = await this.analyticsAdapter.queryIndexer({
8948
- query,
8949
- variables
8950
- });
8951
- const activities = response.activities.map(mapIndexerToVaultActivity);
8952
- return {
8953
- activities,
8954
- total: response.activities_aggregate.aggregate.count
8955
- };
8956
- }
8957
- async getTvlInBaseAsset({ vault, asset }) {
8958
- const normalizedVault = PyxisUtils2.normalizeAddress(vault);
8959
- const normalizedAsset = PyxisUtils2.normalizeAddress(asset);
8960
- const {
8961
- vec: [balance]
8962
- } = await this.chainAdapter.viewContract({
8963
- function: "0x1::fungible_asset::supply",
8964
- typeArguments: ["0x1::fungible_asset::Metadata"],
8965
- arguments: [normalizedVault]
8966
- });
8967
- const functionSignature = this.getBaseFunctionSignature(
8968
- "accountant",
8969
- "calculate_assets_from_shares_safe"
8970
- );
8971
- const baseAssetAmount = await this.chainAdapter.viewContract({
8972
- function: functionSignature,
8973
- arguments: [normalizedVault, normalizedAsset, balance]
8974
- });
8975
- return baseAssetAmount;
8976
- }
8977
- async getUpdateExchangeRateEvents({
8978
- vault,
8979
- startTime,
8980
- endTime
8981
- }) {
8982
- const { query, variables } = buildExchangeRateEventsQuery(
8983
- vault,
8984
- startTime,
8985
- endTime
8986
- );
8987
- const response = await this.analyticsAdapter.queryIndexer({
8988
- query,
8989
- variables
8990
- });
8991
- return response.exchange_rate_updated_events.map(
8992
- PyxisUtils2.mapIndexerToExchangeRateEvent
8993
- );
8994
- }
8995
- async get30DayApy(vault) {
8996
- const startTime = (0, import_dayjs.default)().utc().subtract(THIRTY_DAYS, "day").startOf("day").unix();
8997
- const endTime = (0, import_dayjs.default)().utc().endOf("day").unix();
8998
- const vaultExchangeRateUpdateEvents = await this.getUpdateExchangeRateEvents({
8999
- vault,
9000
- startTime,
9001
- endTime
9002
- });
9003
- if (vaultExchangeRateUpdateEvents.length < MIN_APY_DATA_POINTS) {
9004
- return "0";
9005
- }
9006
- vaultExchangeRateUpdateEvents.sort(
9007
- (a, b) => Number(a.timestamp) - Number(b.timestamp)
9008
- );
9009
- return PyxisUtils2.calculateApy(
9010
- vaultExchangeRateUpdateEvents[0],
9011
- vaultExchangeRateUpdateEvents[vaultExchangeRateUpdateEvents.length - 1]
9012
- );
9013
- }
9014
- async getHistoricalApy({
9015
- vault,
9016
- startTime,
9017
- endTime,
9018
- window = "alltime"
9019
- }) {
9020
- const historicalExchangeRateEvents = await this.getUpdateExchangeRateEvents(
9021
- {
9022
- vault,
9023
- startTime,
9024
- endTime
9025
- }
9026
- );
9027
- if (historicalExchangeRateEvents.length < MIN_APY_DATA_POINTS) {
9028
- return [];
9029
- }
9030
- historicalExchangeRateEvents.sort(
9031
- (a, b) => Number(a.timestamp) - Number(b.timestamp)
9032
- );
9033
- const sampledEvents = PyxisUtils2.sampleEventsByDay(
9034
- historicalExchangeRateEvents
9035
- );
9036
- if (sampledEvents.length < MIN_APY_DATA_POINTS) {
9037
- return [];
9038
- }
9039
- const historicalApyData = sampledEvents.map((event, i) => {
9040
- if (i === 0) return null;
9041
- let baseEventIndex = 0;
9042
- if (window === "alltime") {
9043
- baseEventIndex = 0;
9044
- } else {
9045
- const daysToSubtract = apyWindowDaysMap[window] ?? DEFAULT_APY_WINDOW_DAYS;
9046
- const firstEventTime = import_dayjs.default.unix(Number(sampledEvents[0].timestamp));
9047
- const currentEventTime = import_dayjs.default.unix(Number(event.timestamp));
9048
- if (currentEventTime.diff(firstEventTime, "day") < daysToSubtract) {
9049
- return null;
9050
- }
9051
- const pastTime = currentEventTime.subtract(daysToSubtract, "day");
9052
- for (let j = i - 1; j >= 0; j--) {
9053
- const eventTime = import_dayjs.default.unix(Number(sampledEvents[j].timestamp));
9054
- if (eventTime.isSame(pastTime, "date")) {
9055
- baseEventIndex = j;
9056
- break;
9057
- }
9058
- }
9059
- }
9060
- return {
9061
- value: PyxisUtils2.calculateApy(sampledEvents[baseEventIndex], event),
9062
- timestamp: event.timestamp
9063
- };
9064
- }).filter((item) => item !== null);
9065
- return historicalApyData;
9066
- }
9067
- async getManageOperations(args) {
9068
- return this.statsClient.getManageOperations(args);
9069
- }
9070
- };
9071
-
9072
8668
  // src/evm/adapter.ts
9073
- var import_dayjs2 = __toESM(require_dayjs_min());
8669
+ var import_dayjs = __toESM(require_dayjs_min());
9074
8670
  import { Options as Options2 } from "@layerzerolabs/lz-v2-utilities";
9075
8671
  import {
9076
- BaseChainAdapter as BaseChainAdapter3,
8672
+ BaseChainAdapter as BaseChainAdapter2,
9077
8673
  BridgeMethod as BridgeMethod2,
9078
8674
  ChainId,
9079
- PyxisUtils as PyxisUtils3,
9080
- getChainConfig as getChainConfig3,
8675
+ PyxisUtils as PyxisUtils2,
8676
+ getChainConfig as getChainConfig2,
9081
8677
  getEstimatedBridgeTime as getEstimatedBridgeTime2,
9082
8678
  getLayerZeroEndpointId as getLayerZeroEndpointId2,
9083
8679
  getLayerZeroGasLimit
@@ -9095,7 +8691,7 @@ var viemChainMap = {
9095
8691
  [ChainId.ETHEREUM_SEPOLIA]: sepolia,
9096
8692
  [ChainId.ARBITRUM_ONE]: arbitrum
9097
8693
  };
9098
- var EthereumChainAdapter = class extends BaseChainAdapter3 {
8694
+ var EthereumChainAdapter = class extends BaseChainAdapter2 {
9099
8695
  constructor(chain) {
9100
8696
  super(chain);
9101
8697
  this.viemChain = viemChainMap[chain.id];
@@ -9123,7 +8719,7 @@ var EthereumChainAdapter = class extends BaseChainAdapter3 {
9123
8719
  * Build an Ethereum transaction payload
9124
8720
  */
9125
8721
  async buildPayload(params) {
9126
- const config = getChainConfig3(this.chain.id);
8722
+ const config = getChainConfig2(this.chain.id);
9127
8723
  if (!config.chainId) {
9128
8724
  throw new Error("Chain ID is required for EVM transactions");
9129
8725
  }
@@ -9249,7 +8845,7 @@ var EthereumChainAdapter = class extends BaseChainAdapter3 {
9249
8845
  * Get function signature using the new configuration system
9250
8846
  */
9251
8847
  getFunctionSignature(contractName, functionName) {
9252
- const config = getChainConfig3(this.chain.id);
8848
+ const config = getChainConfig2(this.chain.id);
9253
8849
  const contractAddress = this.getContractAddress(contractName);
9254
8850
  return getFunctionSignature(
9255
8851
  config.type,
@@ -9262,7 +8858,7 @@ var EthereumChainAdapter = class extends BaseChainAdapter3 {
9262
8858
  * Get contract ABI using the new configuration system
9263
8859
  */
9264
8860
  getContractABI(contractName) {
9265
- const config = getChainConfig3(this.chain.id);
8861
+ const config = getChainConfig2(this.chain.id);
9266
8862
  return getContractABI(config.type, contractName);
9267
8863
  }
9268
8864
  async getWithdrawRateInQuoteSafe(args) {
@@ -9334,7 +8930,7 @@ var EthereumChainAdapter = class extends BaseChainAdapter3 {
9334
8930
  "multiChainLzTeller contract address not configured."
9335
8931
  );
9336
8932
  const dstEid = getLayerZeroEndpointId2(destinationChain);
9337
- const config = getChainConfig3(this.chain.id);
8933
+ const config = getChainConfig2(this.chain.id);
9338
8934
  const functionSignature = getFunctionSignature(
9339
8935
  config.type,
9340
8936
  "multiChainLzTeller",
@@ -9374,7 +8970,7 @@ var EthereumChainAdapter = class extends BaseChainAdapter3 {
9374
8970
  lzTellerAddress,
9375
8971
  "Vault does not support bridging. multiChainLzTeller contract address not configured."
9376
8972
  );
9377
- const config = getChainConfig3(this.chain.id);
8973
+ const config = getChainConfig2(this.chain.id);
9378
8974
  const functionSignature = getFunctionSignature(
9379
8975
  config.type,
9380
8976
  "multiChainLzTeller",
@@ -9444,7 +9040,7 @@ var EthereumChainAdapter = class extends BaseChainAdapter3 {
9444
9040
  Number(args.offerAmount),
9445
9041
  false,
9446
9042
  // inSolve: Default false
9447
- (0, import_dayjs2.default)().unix()
9043
+ (0, import_dayjs.default)().unix()
9448
9044
  // UpdatedAt: current unix timestamp
9449
9045
  ]
9450
9046
  ],
@@ -9495,7 +9091,7 @@ var EthereumChainAdapter = class extends BaseChainAdapter3 {
9495
9091
  flag,
9496
9092
  matchAll
9497
9093
  }) {
9498
- const requestFlag = PyxisUtils3.buildRequestFlags(flag);
9094
+ const requestFlag = PyxisUtils2.buildRequestFlags(flag);
9499
9095
  const getAllWithdrawalRequestFn = this.getFunctionSignature(
9500
9096
  "atomicQueue",
9501
9097
  "get_all_atomic_requests"
@@ -9522,7 +9118,7 @@ var EthereumChainAdapter = class extends BaseChainAdapter3 {
9522
9118
  return {
9523
9119
  atomicPrice: request.atomicPrice,
9524
9120
  deadline: request.deadline,
9525
- flags: PyxisUtils3.parseRequestFlags(solveData.flags),
9121
+ flags: PyxisUtils2.parseRequestFlags(solveData.flags),
9526
9122
  offerAmount: request.offerAmount,
9527
9123
  offerToken: request.offerToken,
9528
9124
  userAddress: request.user,
@@ -9555,7 +9151,6 @@ var EthereumChainAdapter = class extends BaseChainAdapter3 {
9555
9151
  export {
9556
9152
  AccountantABI,
9557
9153
  AccountantAptosABI,
9558
- AptosAnalyticsClient,
9559
9154
  AptosChainAdapter,
9560
9155
  AtomicQueueABI,
9561
9156
  AtomicQueueAptosABI,
@@ -9563,12 +9158,10 @@ export {
9563
9158
  CONTRACTS,
9564
9159
  EthereumChainAdapter,
9565
9160
  MultiChainLayerZeroTellerAptosABI,
9566
- PyxisStatsClient,
9567
9161
  TellerAptosABI,
9568
9162
  TellerWithMultiAssetSupportABI,
9569
9163
  VaultAptosABI,
9570
9164
  getContractABI,
9571
- getFunctionSignature,
9572
- mapIndexerToVaultActivity
9165
+ getFunctionSignature
9573
9166
  };
9574
9167
  //# sourceMappingURL=index.mjs.map