@pushchain/core 6.0.20 → 6.0.21

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 (111) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/package.json +1 -1
  3. package/src/lib/cache/cache.js +2 -0
  4. package/src/lib/constants/abi/index.d.ts +1 -0
  5. package/src/lib/constants/abi/index.js +8 -1
  6. package/src/lib/constants/abi/pc20.evm.d.ts +217 -0
  7. package/src/lib/constants/abi/pc20.evm.js +150 -0
  8. package/src/lib/constants/abi/prc20.evm.d.ts +172 -0
  9. package/src/lib/constants/abi/prc20.evm.js +97 -0
  10. package/src/lib/constants/abi/universalGatewayV0.json +1 -1
  11. package/src/lib/constants/chain.js +38 -8
  12. package/src/lib/constants/selectors.js +2 -2
  13. package/src/lib/constants/tokens.js +4 -3
  14. package/src/lib/formatters.js +16 -6
  15. package/src/lib/generated/uexecutor/v1/query.js +2 -4
  16. package/src/lib/generated/uexecutor/v1/types.d.ts +14 -0
  17. package/src/lib/generated/uexecutor/v1/types.js +90 -47
  18. package/src/lib/generated/uexecutor/v2/query.js +2 -4
  19. package/src/lib/generated/uexecutor/v2/types.d.ts +20 -0
  20. package/src/lib/generated/uexecutor/v2/types.js +49 -33
  21. package/src/lib/generated/v1/tx.js +30 -37
  22. package/src/lib/index.d.ts +3 -0
  23. package/src/lib/index.js +21 -3
  24. package/src/lib/internal/buffer.js +1 -2
  25. package/src/lib/orchestrator/cea-utils.js +73 -83
  26. package/src/lib/orchestrator/internals/account-manager.js +130 -139
  27. package/src/lib/orchestrator/internals/cascade.d.ts +0 -6
  28. package/src/lib/orchestrator/internals/cascade.js +1184 -1059
  29. package/src/lib/orchestrator/internals/confirmation.js +138 -148
  30. package/src/lib/orchestrator/internals/error-decoder.js +1 -1
  31. package/src/lib/orchestrator/internals/errors.js +12 -3
  32. package/src/lib/orchestrator/internals/execute-funds-only.d.ts +2 -2
  33. package/src/lib/orchestrator/internals/execute-funds-only.js +297 -259
  34. package/src/lib/orchestrator/internals/execute-funds-payload.d.ts +2 -2
  35. package/src/lib/orchestrator/internals/execute-funds-payload.js +220 -220
  36. package/src/lib/orchestrator/internals/execute-standard.d.ts +0 -8
  37. package/src/lib/orchestrator/internals/execute-standard.js +339 -342
  38. package/src/lib/orchestrator/internals/gas-calculator.js +497 -520
  39. package/src/lib/orchestrator/internals/gas-usd-sizer.js +101 -110
  40. package/src/lib/orchestrator/internals/gateway-client.js +102 -103
  41. package/src/lib/orchestrator/internals/helpers.js +30 -27
  42. package/src/lib/orchestrator/internals/inbound-tracker.js +234 -238
  43. package/src/lib/orchestrator/internals/outbound-sync.js +463 -452
  44. package/src/lib/orchestrator/internals/outbound-tracker.js +27 -34
  45. package/src/lib/orchestrator/internals/payload-builder.d.ts +2 -2
  46. package/src/lib/orchestrator/internals/payload-builder.js +119 -100
  47. package/src/lib/orchestrator/internals/pc-usd-oracle.js +121 -129
  48. package/src/lib/orchestrator/internals/pc20/address-codec.d.ts +31 -0
  49. package/src/lib/orchestrator/internals/pc20/address-codec.js +124 -0
  50. package/src/lib/orchestrator/internals/pc20/chain-namespace.d.ts +68 -0
  51. package/src/lib/orchestrator/internals/pc20/chain-namespace.js +136 -0
  52. package/src/lib/orchestrator/internals/pc20/errors.d.ts +160 -0
  53. package/src/lib/orchestrator/internals/pc20/errors.js +236 -0
  54. package/src/lib/orchestrator/internals/pc20/export.d.ts +172 -0
  55. package/src/lib/orchestrator/internals/pc20/export.js +412 -0
  56. package/src/lib/orchestrator/internals/pc20/gate.d.ts +67 -0
  57. package/src/lib/orchestrator/internals/pc20/gate.js +184 -0
  58. package/src/lib/orchestrator/internals/pc20/resolver.d.ts +187 -0
  59. package/src/lib/orchestrator/internals/pc20/resolver.js +658 -0
  60. package/src/lib/orchestrator/internals/pc20/svm.d.ts +189 -0
  61. package/src/lib/orchestrator/internals/pc20/svm.js +286 -0
  62. package/src/lib/orchestrator/internals/pc20/tracking.d.ts +46 -0
  63. package/src/lib/orchestrator/internals/pc20/tracking.js +109 -0
  64. package/src/lib/orchestrator/internals/preflight.js +1 -1
  65. package/src/lib/orchestrator/internals/progress-route-hooks.js +2 -2
  66. package/src/lib/orchestrator/internals/push-chain-tx.js +319 -329
  67. package/src/lib/orchestrator/internals/quote.js +90 -94
  68. package/src/lib/orchestrator/internals/rescue.js +76 -79
  69. package/src/lib/orchestrator/internals/response-builder.d.ts +28 -1
  70. package/src/lib/orchestrator/internals/response-builder.js +817 -701
  71. package/src/lib/orchestrator/internals/route-handlers.d.ts +7 -15
  72. package/src/lib/orchestrator/internals/route-handlers.js +1512 -1178
  73. package/src/lib/orchestrator/internals/signing.js +78 -83
  74. package/src/lib/orchestrator/internals/svm-bridge.d.ts +2 -2
  75. package/src/lib/orchestrator/internals/svm-bridge.js +161 -93
  76. package/src/lib/orchestrator/internals/svm-helpers.d.ts +15 -1
  77. package/src/lib/orchestrator/internals/svm-helpers.js +68 -24
  78. package/src/lib/orchestrator/internals/svm-rent.d.ts +19 -1
  79. package/src/lib/orchestrator/internals/svm-rent.js +163 -141
  80. package/src/lib/orchestrator/internals/tx-transformer.js +26 -23
  81. package/src/lib/orchestrator/internals/uea-manager.js +89 -86
  82. package/src/lib/orchestrator/max-pc-for-gas.js +5 -6
  83. package/src/lib/orchestrator/orchestrator.js +217 -200
  84. package/src/lib/orchestrator/orchestrator.types.d.ts +121 -1
  85. package/src/lib/orchestrator/orchestrator.types.js +19 -0
  86. package/src/lib/orchestrator/payload-builders.d.ts +2 -2
  87. package/src/lib/orchestrator/payload-builders.js +26 -24
  88. package/src/lib/orchestrator/route-detector.js +26 -9
  89. package/src/lib/orchestrator/svm-idl/ix-encoder.js +1 -2
  90. package/src/lib/orchestrator/svm-idl/normalize-address.js +2 -2
  91. package/src/lib/orchestrator/svm-idl/resolve.js +1 -2
  92. package/src/lib/price-fetch/price-fetch.js +67 -68
  93. package/src/lib/progress-hook/progress-hook.js +124 -72
  94. package/src/lib/push-chain/push-chain.js +171 -153
  95. package/src/lib/push-client/push-client.js +223 -237
  96. package/src/lib/universal/account/account.js +349 -365
  97. package/src/lib/universal/signer/signer.js +306 -294
  98. package/src/lib/universal-tx-detector/auto-detect.js +55 -60
  99. package/src/lib/universal-tx-detector/cascade.js +160 -172
  100. package/src/lib/universal-tx-detector/child-inbounds.js +67 -75
  101. package/src/lib/universal-tx-detector/classify.js +2 -3
  102. package/src/lib/universal-tx-detector/detector-svm.js +139 -147
  103. package/src/lib/universal-tx-detector/detector.js +145 -157
  104. package/src/lib/universal-tx-detector/normalize.js +7 -7
  105. package/src/lib/utils/external-tx-hash.js +1 -2
  106. package/src/lib/utils.d.ts +44 -0
  107. package/src/lib/utils.js +762 -683
  108. package/src/lib/vm-client/evm-client.js +186 -202
  109. package/src/lib/vm-client/svm-client.d.ts +1 -1
  110. package/src/lib/vm-client/svm-client.js +220 -224
  111. package/src/lib/vm-client/vm-client.types.d.ts +14 -2
@@ -1,8 +1,6 @@
1
1
  "use strict";
2
- var _a;
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.PushChain = void 0;
5
- const tslib_1 = require("tslib");
6
4
  const constants_1 = require("../constants");
7
5
  const enums_1 = require("../constants/enums");
8
6
  const chain_1 = require("../constants/chain");
@@ -20,41 +18,54 @@ const tokens_1 = require("../constants/tokens");
20
18
  * Provides access to cross-chain execution, utilities, and signer abstraction.
21
19
  */
22
20
  class PushChain {
21
+ orchestrator;
22
+ universalSigner;
23
+ blockExplorers;
24
+ isReadMode;
25
+ /**
26
+ * @static
27
+ * Constants for the PushChain SDK.
28
+ */
29
+ static CONSTANTS = constants_1.CONSTANTS;
30
+ /**
31
+ * @static
32
+ * Utility functions for encoding, hashing, and data formatting.
33
+ */
34
+ static utils = utils_1.Utils;
23
35
  /**
24
36
  * Helper function to check if input is UniversalAccount (read-only) or UniversalSigner
25
37
  */
26
38
  static isUniversalAccount(input) {
27
39
  return !('signMessage' in input) && !('signAndSendTransaction' in input);
28
40
  }
41
+ /**
42
+ * Universal namespace containing core transaction and address computation methods
43
+ */
44
+ universal;
45
+ explorer;
46
+ /**
47
+ * Moveable and payable token registries exposed on the client instance.
48
+ * These are derived from the origin chain and only include tokens available for that chain.
49
+ */
50
+ moveable;
51
+ payable;
52
+ funds;
53
+ /**
54
+ * Account status including UEA deployment state and version info.
55
+ * Initially unloaded — call getAccountStatus() to populate.
56
+ */
57
+ accountStatus;
58
+ /**
59
+ * Promise for the background account status fetch started during initialize().
60
+ * Await this if you need to ensure account status is loaded before proceeding.
61
+ * Resolves to void (result is stored in accountStatus).
62
+ */
63
+ accountStatusReady;
29
64
  constructor(orchestrator, universalSigner, blockExplorers, isReadMode) {
30
- var _b, _c, _d, _e, _f, _g;
31
65
  this.orchestrator = orchestrator;
32
66
  this.universalSigner = universalSigner;
33
67
  this.blockExplorers = blockExplorers;
34
68
  this.isReadMode = isReadMode;
35
- /**
36
- * @method reinitialize
37
- * Reinitializes the PushChain SDK with a new universal signer and optional config.
38
- *
39
- * @param universalSigner
40
- * @param options - Optional settings to configure the SDK instance.
41
- * - network: PushChain network to target (e.g., TESTNET_DONUT, MAINNET).
42
- * - rpcUrls: Custom RPC URLs mapped by chain IDs.
43
- * - printTraces: Whether to print internal trace logs for debugging.
44
- *
45
- * @returns A new initialized instance of PushChain.
46
- */
47
- this.reinitialize = (universalSigner, options) => tslib_1.__awaiter(this, void 0, void 0, function* () {
48
- var _b, _c, _d, _e, _f;
49
- const mergedOptions = {
50
- network: (_b = options === null || options === void 0 ? void 0 : options.network) !== null && _b !== void 0 ? _b : this.orchestrator.getNetwork(),
51
- rpcUrls: (_c = options === null || options === void 0 ? void 0 : options.rpcUrls) !== null && _c !== void 0 ? _c : this.orchestrator.getRpcUrls(),
52
- blockExplorers: (_d = options === null || options === void 0 ? void 0 : options.blockExplorers) !== null && _d !== void 0 ? _d : this.blockExplorers,
53
- printTraces: (_e = options === null || options === void 0 ? void 0 : options.printTraces) !== null && _e !== void 0 ? _e : this.orchestrator.getPrintTraces(),
54
- progressHook: (_f = options === null || options === void 0 ? void 0 : options.progressHook) !== null && _f !== void 0 ? _f : this.orchestrator.getProgressHook(),
55
- };
56
- return _a.createInstance(universalSigner, mergedOptions);
57
- });
58
69
  this.orchestrator = orchestrator;
59
70
  this.accountStatus = {
60
71
  mode: isReadMode ? 'read-only' : 'signer',
@@ -84,12 +95,12 @@ class PushChain {
84
95
  prepareTransaction: (params, options) => {
85
96
  return orchestrator.prepareTransaction.bind(orchestrator)(params, options);
86
97
  },
87
- executeTransactions: (txs, options) => tslib_1.__awaiter(this, void 0, void 0, function* () {
98
+ executeTransactions: async (txs, options) => {
88
99
  if (this.isReadMode) {
89
100
  throw new Error('Read only mode cannot call executeTransactions function');
90
101
  }
91
102
  return orchestrator.createCascadedBuilder(txs, options).send();
92
- }),
103
+ },
93
104
  trackTransaction: (txHash, options) => {
94
105
  return orchestrator.trackTransaction.bind(orchestrator)(txHash, options);
95
106
  },
@@ -105,11 +116,11 @@ class PushChain {
105
116
  }
106
117
  return orchestrator.rescueFunds.bind(orchestrator)(params);
107
118
  },
108
- signMessage: (data) => tslib_1.__awaiter(this, void 0, void 0, function* () {
119
+ signMessage: async (data) => {
109
120
  if (this.isReadMode) {
110
121
  throw new Error('Read only mode cannot call signMessage function');
111
122
  }
112
- const sigBytes = yield universalSigner.signMessage(data);
123
+ const sigBytes = await universalSigner.signMessage(data);
113
124
  const chain = universalSigner.account.chain;
114
125
  if (chain_1.CHAIN_INFO[chain].vm === enums_1.VM.EVM) {
115
126
  return (0, viem_1.bytesToHex)(sigBytes);
@@ -118,24 +129,24 @@ class PushChain {
118
129
  return bs58_1.bs58.encode(Buffer.from(sigBytes));
119
130
  }
120
131
  return (0, viem_1.bytesToHex)(sigBytes);
121
- }),
122
- signTypedData: (...args) => tslib_1.__awaiter(this, void 0, void 0, function* () {
132
+ },
133
+ signTypedData: async (...args) => {
123
134
  if (typeof universalSigner.signTypedData !== 'function') {
124
135
  throw new Error('Typed data signing not supported');
125
136
  }
126
- const signBytes = yield universalSigner.signTypedData(...args);
137
+ const signBytes = await universalSigner.signTypedData(...args);
127
138
  return (0, viem_1.bytesToHex)(signBytes);
128
- }),
139
+ },
129
140
  };
130
141
  const network = orchestrator.getNetwork() === enums_1.PUSH_NETWORK.MAINNET
131
142
  ? 'mainnet'
132
143
  : 'testnet';
133
144
  this.explorer = {
134
145
  getTransactionUrl: (txHash, options) => {
135
- if (options === null || options === void 0 ? void 0 : options.chain) {
146
+ if (options?.chain) {
136
147
  // Use user-provided block explorers first, then fall back to built-in
137
148
  const userUrls = blockExplorers[options.chain];
138
- if (userUrls === null || userUrls === void 0 ? void 0 : userUrls.length) {
149
+ if (userUrls?.length) {
139
150
  return `${userUrls[0]}/tx/${txHash}`;
140
151
  }
141
152
  const builtInUrl = (0, chain_1.getExplorerTxUrl)(txHash, options.chain, network);
@@ -144,22 +155,21 @@ class PushChain {
144
155
  }
145
156
  // Default: Push Chain explorer
146
157
  const pushUrls = blockExplorers[enums_1.CHAIN.PUSH_TESTNET_DONUT];
147
- if (pushUrls === null || pushUrls === void 0 ? void 0 : pushUrls.length) {
158
+ if (pushUrls?.length) {
148
159
  return `${pushUrls[0]}/tx/${txHash}`;
149
160
  }
150
161
  return `https://donut.push.network/tx/${txHash}`;
151
162
  },
152
163
  listUrls: (options) => {
153
- var _b, _c, _d;
154
- const targetChain = (_b = options === null || options === void 0 ? void 0 : options.chain) !== null && _b !== void 0 ? _b : enums_1.CHAIN.PUSH_TESTNET_DONUT;
164
+ const targetChain = options?.chain ?? enums_1.CHAIN.PUSH_TESTNET_DONUT;
155
165
  // Check user-provided block explorers first
156
166
  const userUrls = blockExplorers[targetChain];
157
- if (userUrls === null || userUrls === void 0 ? void 0 : userUrls.length) {
167
+ if (userUrls?.length) {
158
168
  return {
159
169
  explorers: [
160
170
  {
161
171
  chain: targetChain,
162
- chainName: (_c = utils_1.Utils.chains.getChainName(targetChain)) !== null && _c !== void 0 ? _c : targetChain,
172
+ chainName: utils_1.Utils.chains.getChainName(targetChain) ?? targetChain,
163
173
  urls: userUrls,
164
174
  },
165
175
  ],
@@ -167,19 +177,18 @@ class PushChain {
167
177
  }
168
178
  // Fall back to built-in CHAIN_EXPLORERS
169
179
  const explorers = chain_1.CHAIN_EXPLORERS[targetChain];
170
- const builtInUrls = network === 'mainnet' ? explorers === null || explorers === void 0 ? void 0 : explorers.mainnet : explorers === null || explorers === void 0 ? void 0 : explorers.testnet;
180
+ const builtInUrls = network === 'mainnet' ? explorers?.mainnet : explorers?.testnet;
171
181
  return {
172
182
  explorers: [
173
183
  {
174
184
  chain: targetChain,
175
- chainName: (_d = utils_1.Utils.chains.getChainName(targetChain)) !== null && _d !== void 0 ? _d : targetChain,
176
- urls: builtInUrls !== null && builtInUrls !== void 0 ? builtInUrls : [],
185
+ chainName: utils_1.Utils.chains.getChainName(targetChain) ?? targetChain,
186
+ urls: builtInUrls ?? [],
177
187
  },
178
188
  ],
179
189
  };
180
190
  },
181
191
  listAllUrls: () => {
182
- var _b, _c;
183
192
  const result = [];
184
193
  // Collect all chains from both built-in and user-provided explorers
185
194
  const allChains = new Set([
@@ -189,21 +198,21 @@ class PushChain {
189
198
  for (const chain of allChains) {
190
199
  // User overrides take precedence
191
200
  const userUrls = blockExplorers[chain];
192
- if (userUrls === null || userUrls === void 0 ? void 0 : userUrls.length) {
201
+ if (userUrls?.length) {
193
202
  result.push({
194
203
  chain,
195
- chainName: (_b = utils_1.Utils.chains.getChainName(chain)) !== null && _b !== void 0 ? _b : chain,
204
+ chainName: utils_1.Utils.chains.getChainName(chain) ?? chain,
196
205
  urls: userUrls,
197
206
  });
198
207
  continue;
199
208
  }
200
209
  // Built-in CHAIN_EXPLORERS
201
210
  const explorers = chain_1.CHAIN_EXPLORERS[chain];
202
- const builtInUrls = network === 'mainnet' ? explorers === null || explorers === void 0 ? void 0 : explorers.mainnet : explorers === null || explorers === void 0 ? void 0 : explorers.testnet;
203
- if (builtInUrls === null || builtInUrls === void 0 ? void 0 : builtInUrls.length) {
211
+ const builtInUrls = network === 'mainnet' ? explorers?.mainnet : explorers?.testnet;
212
+ if (builtInUrls?.length) {
204
213
  result.push({
205
214
  chain,
206
- chainName: (_c = utils_1.Utils.chains.getChainName(chain)) !== null && _c !== void 0 ? _c : chain,
215
+ chainName: utils_1.Utils.chains.getChainName(chain) ?? chain,
207
216
  urls: builtInUrls,
208
217
  });
209
218
  }
@@ -213,12 +222,18 @@ class PushChain {
213
222
  };
214
223
  // Derive moveable/payable tokens for the current origin chain
215
224
  const originChain = universalSigner.account.chain;
216
- const toTokenMap = (arr) => (arr !== null && arr !== void 0 ? arr : []).reduce((acc, t) => {
225
+ const toTokenMap = (arr) => (arr ?? []).reduce((acc, t) => {
217
226
  acc[t.symbol] = t;
218
227
  return acc;
219
228
  }, {});
220
- const moveableList = (_d = (_c = (_b = tokens_1.MOVEABLE_TOKENS[originChain]) !== null && _b !== void 0 ? _b : tokens_1.MOVEABLE_TOKENS[enums_1.CHAIN.ETHEREUM_MAINNET]) !== null && _c !== void 0 ? _c : tokens_1.MOVEABLE_TOKENS[enums_1.CHAIN.ETHEREUM_SEPOLIA]) !== null && _d !== void 0 ? _d : [];
221
- const payableList = (_g = (_f = (_e = tokens_1.PAYABLE_TOKENS[originChain]) !== null && _e !== void 0 ? _e : tokens_1.PAYABLE_TOKENS[enums_1.CHAIN.ETHEREUM_MAINNET]) !== null && _f !== void 0 ? _f : tokens_1.PAYABLE_TOKENS[enums_1.CHAIN.ETHEREUM_SEPOLIA]) !== null && _g !== void 0 ? _g : [];
229
+ const moveableList = tokens_1.MOVEABLE_TOKENS[originChain] ??
230
+ tokens_1.MOVEABLE_TOKENS[enums_1.CHAIN.ETHEREUM_MAINNET] ??
231
+ tokens_1.MOVEABLE_TOKENS[enums_1.CHAIN.ETHEREUM_SEPOLIA] ??
232
+ [];
233
+ const payableList = tokens_1.PAYABLE_TOKENS[originChain] ??
234
+ tokens_1.PAYABLE_TOKENS[enums_1.CHAIN.ETHEREUM_MAINNET] ??
235
+ tokens_1.PAYABLE_TOKENS[enums_1.CHAIN.ETHEREUM_SEPOLIA] ??
236
+ [];
222
237
  this.moveable = {
223
238
  token: new tokens_1.MoveableTokenAccessor(toTokenMap(moveableList)),
224
239
  };
@@ -226,8 +241,7 @@ class PushChain {
226
241
  token: new tokens_1.PayableTokenAccessor(toTokenMap(payableList)),
227
242
  };
228
243
  this.funds = {
229
- getConversionQuote: (amountIn_1, _b) => tslib_1.__awaiter(this, [amountIn_1, _b], void 0, function* (amountIn, { from, to, }) {
230
- var _c, _d, _e;
244
+ getConversionQuote: async (amountIn, { from, to, }) => {
231
245
  const originChain = universalSigner.account.chain;
232
246
  if (originChain !== enums_1.CHAIN.ETHEREUM_SEPOLIA) {
233
247
  throw new Error('getConversionQuote is only supported on Ethereum Sepolia for now');
@@ -243,8 +257,8 @@ class PushChain {
243
257
  chain_1.CHAIN_INFO[originChain].defaultRPC;
244
258
  const evm = new evm_client_1.EvmClient({ rpcUrls });
245
259
  // Minimal ABIs and Uniswap V3 addresses sourced from chain config
246
- const factoryFromConfig = (_c = chain_1.CHAIN_INFO[originChain].dex) === null || _c === void 0 ? void 0 : _c.uniV3Factory;
247
- const quoterFromConfig = (_d = chain_1.CHAIN_INFO[originChain].dex) === null || _d === void 0 ? void 0 : _d.uniV3QuoterV2;
260
+ const factoryFromConfig = chain_1.CHAIN_INFO[originChain].dex?.uniV3Factory;
261
+ const quoterFromConfig = chain_1.CHAIN_INFO[originChain].dex?.uniV3QuoterV2;
248
262
  if (!factoryFromConfig || !quoterFromConfig) {
249
263
  throw new Error('Uniswap V3 addresses not configured for this chain');
250
264
  }
@@ -264,7 +278,7 @@ class PushChain {
264
278
  let bestFee = null;
265
279
  for (const fee of feeTiers) {
266
280
  // Find pool address for this fee tier
267
- const poolAddress = yield evm.readContract({
281
+ const poolAddress = await evm.readContract({
268
282
  abi: factoryAbi,
269
283
  address: UNISWAP_V3_FACTORY,
270
284
  functionName: 'getPool',
@@ -277,7 +291,7 @@ class PushChain {
277
291
  continue;
278
292
  // Skip uninitialized/empty pools to avoid Quoter reverts
279
293
  try {
280
- const liquidity = yield evm.readContract({
294
+ const liquidity = await evm.readContract({
281
295
  abi: poolAbi,
282
296
  address: poolAddress,
283
297
  functionName: 'liquidity',
@@ -287,13 +301,13 @@ class PushChain {
287
301
  continue;
288
302
  }
289
303
  }
290
- catch (_f) {
304
+ catch {
291
305
  // If we can't read liquidity, skip this pool/fee tier
292
306
  continue;
293
307
  }
294
308
  // Quote exact input single for this fee tier; catch reverts due to empty/uninitialized pools
295
309
  try {
296
- const result = yield evm.readContract({
310
+ const result = await evm.readContract({
297
311
  abi: quoterAbi,
298
312
  address: UNISWAP_V3_QUOTER_V2,
299
313
  functionName: 'quoteExactInputSingle',
@@ -307,13 +321,13 @@ class PushChain {
307
321
  },
308
322
  ],
309
323
  });
310
- const amountOut = (_e = result === null || result === void 0 ? void 0 : result[0]) !== null && _e !== void 0 ? _e : BigInt(0);
324
+ const amountOut = result?.[0] ?? BigInt(0);
311
325
  if (amountOut > bestAmountOut) {
312
326
  bestAmountOut = amountOut;
313
327
  bestFee = fee;
314
328
  }
315
329
  }
316
- catch (_g) {
330
+ catch {
317
331
  // try next fee
318
332
  }
319
333
  }
@@ -331,19 +345,17 @@ class PushChain {
331
345
  route: [from.symbol, to.symbol],
332
346
  timestamp: Date.now(),
333
347
  };
334
- }),
348
+ },
335
349
  };
336
350
  }
337
351
  /**
338
352
  * Fetches the account status including UEA deployment state and version info.
339
353
  * Results are cached — pass forceRefresh to bypass cache.
340
354
  */
341
- getAccountStatus(options) {
342
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
343
- const status = yield this.orchestrator.getAccountStatus(options);
344
- this.accountStatus = status;
345
- return status;
346
- });
355
+ async getAccountStatus(options) {
356
+ const status = await this.orchestrator.getAccountStatus(options);
357
+ this.accountStatus = status;
358
+ return status;
347
359
  }
348
360
  /**
349
361
  * Upgrades the UEA to the latest implementation version.
@@ -351,16 +363,14 @@ class PushChain {
351
363
  *
352
364
  * @throws Error if called in read-only mode
353
365
  */
354
- upgradeAccount(options) {
355
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
356
- if (this.isReadMode) {
357
- throw new Error('Read only mode cannot call upgradeAccount function');
358
- }
359
- yield this.orchestrator.upgradeAccount(options);
360
- // Refresh local accountStatus after upgrade
361
- this.accountStatus = yield this.orchestrator.getAccountStatus({
362
- forceRefresh: true,
363
- });
366
+ async upgradeAccount(options) {
367
+ if (this.isReadMode) {
368
+ throw new Error('Read only mode cannot call upgradeAccount function');
369
+ }
370
+ await this.orchestrator.upgradeAccount(options);
371
+ // Refresh local accountStatus after upgrade
372
+ this.accountStatus = await this.orchestrator.getAccountStatus({
373
+ forceRefresh: true,
364
374
  });
365
375
  }
366
376
  /**
@@ -368,82 +378,90 @@ class PushChain {
368
378
  * Internal method to create a PushChain instance with the given parameters.
369
379
  * Used by both initialize and reinitialize methods to avoid code duplication.
370
380
  */
371
- static createInstance(universalSigner, options) {
372
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
373
- var _b, _c, _d, _e;
374
- const isReadOnly = _a.isUniversalAccount(universalSigner);
375
- // If it's a UniversalAccount (read-only), create a dummy signer for the orchestrator
376
- const validatedUniversalSigner = isReadOnly
377
- ? (0, signer_1.createUniversalSigner)({
378
- account: universalSigner,
379
- signMessage: () => tslib_1.__awaiter(this, void 0, void 0, function* () {
380
- throw new Error('Read only mode cannot call signMessage function');
381
- }),
382
- signAndSendTransaction: () => tslib_1.__awaiter(this, void 0, void 0, function* () {
383
- throw new Error('Read only mode cannot call signAndSendTransaction function');
384
- }),
385
- })
386
- : (0, signer_1.createUniversalSigner)(universalSigner);
387
- const blockExplorers = (_b = options === null || options === void 0 ? void 0 : options.blockExplorers) !== null && _b !== void 0 ? _b : {
388
- [enums_1.CHAIN.PUSH_TESTNET_DONUT]: ['https://donut.push.network'],
389
- };
390
- const orchestrator = new orchestrator_1.Orchestrator(
391
- /**
392
- * Ensures the signer conforms to the UniversalSigner interface.
393
- */
394
- validatedUniversalSigner, (_c = options === null || options === void 0 ? void 0 : options.network) !== null && _c !== void 0 ? _c : enums_1.PUSH_NETWORK.TESTNET_DONUT, (_d = options === null || options === void 0 ? void 0 : options.rpcUrls) !== null && _d !== void 0 ? _d : {}, (_e = options === null || options === void 0 ? void 0 : options.printTraces) !== null && _e !== void 0 ? _e : false, options === null || options === void 0 ? void 0 : options.progressHook);
395
- const instance = new _a(orchestrator, validatedUniversalSigner, blockExplorers, isReadOnly);
396
- // Background fetch account status (non-blocking, 30s timeout).
397
- // The timer must be cleared once the race settles — otherwise the
398
- // unref'd setTimeout keeps the Node event loop alive for the full
399
- // 30s after the caller's work is done, making scripts appear "stuck".
400
- const ACCOUNT_STATUS_TIMEOUT = 30000;
401
- let accountStatusTimer;
402
- instance.accountStatusReady = Promise.race([
403
- // eslint-disable-next-line @typescript-eslint/no-empty-function
404
- instance.getAccountStatus().then(() => { }),
405
- new Promise((_, reject) => {
406
- accountStatusTimer = setTimeout(() => reject(new Error('Account status fetch timed out')), ACCOUNT_STATUS_TIMEOUT);
407
- }),
408
- ])
409
- .catch(() => {
410
- // Silently ignore — lazy check in execute() will retry if needed
381
+ static async createInstance(universalSigner, options) {
382
+ const isReadOnly = PushChain.isUniversalAccount(universalSigner);
383
+ // If it's a UniversalAccount (read-only), create a dummy signer for the orchestrator
384
+ const validatedUniversalSigner = isReadOnly
385
+ ? (0, signer_1.createUniversalSigner)({
386
+ account: universalSigner,
387
+ signMessage: async () => {
388
+ throw new Error('Read only mode cannot call signMessage function');
389
+ },
390
+ signAndSendTransaction: async () => {
391
+ throw new Error('Read only mode cannot call signAndSendTransaction function');
392
+ },
411
393
  })
412
- .finally(() => {
413
- if (accountStatusTimer)
414
- clearTimeout(accountStatusTimer);
415
- });
416
- // Let execute() await the background fetch instead of re-fetching
417
- orchestrator.accountStatusReadyPromise = instance.accountStatusReady;
418
- return instance;
394
+ : (0, signer_1.createUniversalSigner)(universalSigner);
395
+ const blockExplorers = options?.blockExplorers ?? {
396
+ [enums_1.CHAIN.PUSH_TESTNET_DONUT]: ['https://donut.push.network'],
397
+ };
398
+ const orchestrator = new orchestrator_1.Orchestrator(
399
+ /**
400
+ * Ensures the signer conforms to the UniversalSigner interface.
401
+ */
402
+ validatedUniversalSigner, options?.network ?? enums_1.PUSH_NETWORK.TESTNET_DONUT, options?.rpcUrls ?? {}, options?.printTraces ?? false, options?.progressHook);
403
+ const instance = new PushChain(orchestrator, validatedUniversalSigner, blockExplorers, isReadOnly);
404
+ // Background fetch account status (non-blocking, 30s timeout).
405
+ // The timer must be cleared once the race settles — otherwise the
406
+ // unref'd setTimeout keeps the Node event loop alive for the full
407
+ // 30s after the caller's work is done, making scripts appear "stuck".
408
+ const ACCOUNT_STATUS_TIMEOUT = 30_000;
409
+ let accountStatusTimer;
410
+ instance.accountStatusReady = Promise.race([
411
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
412
+ instance.getAccountStatus().then(() => { }),
413
+ new Promise((_, reject) => {
414
+ accountStatusTimer = setTimeout(() => reject(new Error('Account status fetch timed out')), ACCOUNT_STATUS_TIMEOUT);
415
+ }),
416
+ ])
417
+ .catch(() => {
418
+ // Silently ignore — lazy check in execute() will retry if needed
419
+ })
420
+ .finally(() => {
421
+ if (accountStatusTimer)
422
+ clearTimeout(accountStatusTimer);
419
423
  });
424
+ // Let execute() await the background fetch instead of re-fetching
425
+ orchestrator.accountStatusReadyPromise = instance.accountStatusReady;
426
+ return instance;
420
427
  }
428
+ /**
429
+ * @method initialize
430
+ * Initializes the PushChain SDK with a universal signer and optional config.
431
+ *
432
+ * @param universalSigner
433
+ * @param options - Optional settings to configure the SDK instance.
434
+ * - network: PushChain network to target (e.g., TESTNET_DONUT, MAINNET).
435
+ * - rpcUrls: Custom RPC URLs mapped by chain IDs.
436
+ * - printTraces: Whether to print internal trace logs for debugging.
437
+ *
438
+ * @returns An initialized instance of PushChain.
439
+ */
440
+ static initialize = async (universalSigner, options) => {
441
+ return PushChain.createInstance(universalSigner, options);
442
+ };
443
+ /**
444
+ * @method reinitialize
445
+ * Reinitializes the PushChain SDK with a new universal signer and optional config.
446
+ *
447
+ * @param universalSigner
448
+ * @param options - Optional settings to configure the SDK instance.
449
+ * - network: PushChain network to target (e.g., TESTNET_DONUT, MAINNET).
450
+ * - rpcUrls: Custom RPC URLs mapped by chain IDs.
451
+ * - printTraces: Whether to print internal trace logs for debugging.
452
+ *
453
+ * @returns A new initialized instance of PushChain.
454
+ */
455
+ reinitialize = async (universalSigner, options) => {
456
+ const mergedOptions = {
457
+ network: options?.network ?? this.orchestrator.getNetwork(),
458
+ rpcUrls: options?.rpcUrls ?? this.orchestrator.getRpcUrls(),
459
+ blockExplorers: options?.blockExplorers ?? this.blockExplorers,
460
+ printTraces: options?.printTraces ?? this.orchestrator.getPrintTraces(),
461
+ progressHook: options?.progressHook ?? this.orchestrator.getProgressHook(),
462
+ };
463
+ return PushChain.createInstance(universalSigner, mergedOptions);
464
+ };
421
465
  }
422
466
  exports.PushChain = PushChain;
423
- _a = PushChain;
424
- /**
425
- * @static
426
- * Constants for the PushChain SDK.
427
- */
428
- PushChain.CONSTANTS = constants_1.CONSTANTS;
429
- /**
430
- * @static
431
- * Utility functions for encoding, hashing, and data formatting.
432
- */
433
- PushChain.utils = utils_1.Utils;
434
- /**
435
- * @method initialize
436
- * Initializes the PushChain SDK with a universal signer and optional config.
437
- *
438
- * @param universalSigner
439
- * @param options - Optional settings to configure the SDK instance.
440
- * - network: PushChain network to target (e.g., TESTNET_DONUT, MAINNET).
441
- * - rpcUrls: Custom RPC URLs mapped by chain IDs.
442
- * - printTraces: Whether to print internal trace logs for debugging.
443
- *
444
- * @returns An initialized instance of PushChain.
445
- */
446
- PushChain.initialize = (universalSigner, options) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
447
- return _a.createInstance(universalSigner, options);
448
- });
449
467
  //# sourceMappingURL=push-chain.js.map