@pushchain/core 5.1.3 → 5.1.4-alpha.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.
Files changed (131) hide show
  1. package/package.json +29 -6
  2. package/src/lib/constants/abi/prc20.evm.d.ts +22 -2
  3. package/src/lib/constants/abi/prc20.evm.js +11 -3
  4. package/src/lib/constants/abi/universalGatewayPC.evm.d.ts +59 -0
  5. package/src/lib/constants/abi/universalGatewayPC.evm.js +26 -0
  6. package/src/lib/constants/chain.d.ts +4 -0
  7. package/src/lib/constants/chain.js +6 -2
  8. package/src/lib/index.d.ts +2 -2
  9. package/src/lib/internal/bs58.d.ts +2 -0
  10. package/src/lib/internal/bs58.js +7 -0
  11. package/src/lib/orchestrator/cea-utils.d.ts +0 -9
  12. package/src/lib/orchestrator/cea-utils.js +15 -4
  13. package/src/lib/orchestrator/internals/account-manager.d.ts +16 -0
  14. package/src/lib/orchestrator/internals/account-manager.js +191 -0
  15. package/src/lib/orchestrator/internals/cascade.d.ts +23 -0
  16. package/src/lib/orchestrator/internals/cascade.js +945 -0
  17. package/src/lib/orchestrator/internals/confirmation.d.ts +9 -0
  18. package/src/lib/orchestrator/internals/confirmation.js +123 -0
  19. package/src/lib/orchestrator/internals/context.d.ts +38 -0
  20. package/src/lib/orchestrator/internals/context.js +49 -0
  21. package/src/lib/orchestrator/internals/execute-funds-only.d.ts +11 -0
  22. package/src/lib/orchestrator/internals/execute-funds-only.js +219 -0
  23. package/src/lib/orchestrator/internals/execute-funds-payload.d.ts +11 -0
  24. package/src/lib/orchestrator/internals/execute-funds-payload.js +222 -0
  25. package/src/lib/orchestrator/internals/execute-standard.d.ts +13 -0
  26. package/src/lib/orchestrator/internals/execute-standard.js +225 -0
  27. package/src/lib/orchestrator/internals/gas-calculator.d.ts +38 -0
  28. package/src/lib/orchestrator/internals/gas-calculator.js +424 -0
  29. package/src/lib/orchestrator/internals/gateway-client.d.ts +24 -0
  30. package/src/lib/orchestrator/internals/gateway-client.js +191 -0
  31. package/src/lib/orchestrator/internals/helpers.d.ts +26 -0
  32. package/src/lib/orchestrator/internals/helpers.js +181 -0
  33. package/src/lib/orchestrator/internals/index.d.ts +24 -0
  34. package/src/lib/orchestrator/internals/index.js +132 -0
  35. package/src/lib/orchestrator/internals/outbound-sync.d.ts +49 -0
  36. package/src/lib/orchestrator/internals/outbound-sync.js +357 -0
  37. package/src/lib/orchestrator/internals/outbound-tracker.d.ts +8 -0
  38. package/src/lib/orchestrator/internals/outbound-tracker.js +64 -0
  39. package/src/lib/orchestrator/internals/payload-builder.d.ts +24 -0
  40. package/src/lib/orchestrator/internals/payload-builder.js +178 -0
  41. package/src/lib/orchestrator/internals/push-chain-tx.d.ts +32 -0
  42. package/src/lib/orchestrator/internals/push-chain-tx.js +207 -0
  43. package/src/lib/orchestrator/internals/quote.d.ts +9 -0
  44. package/src/lib/orchestrator/internals/quote.js +114 -0
  45. package/src/lib/orchestrator/internals/rescue.d.ts +20 -0
  46. package/src/lib/orchestrator/internals/rescue.js +112 -0
  47. package/src/lib/orchestrator/internals/response-builder.d.ts +26 -0
  48. package/src/lib/orchestrator/internals/response-builder.js +504 -0
  49. package/src/lib/orchestrator/internals/route-handlers.d.ts +77 -0
  50. package/src/lib/orchestrator/internals/route-handlers.js +1192 -0
  51. package/src/lib/orchestrator/internals/signing.d.ts +27 -0
  52. package/src/lib/orchestrator/internals/signing.js +258 -0
  53. package/src/lib/orchestrator/internals/svm-bridge.d.ts +21 -0
  54. package/src/lib/orchestrator/internals/svm-bridge.js +122 -0
  55. package/src/lib/orchestrator/internals/svm-helpers.d.ts +35 -0
  56. package/src/lib/orchestrator/internals/svm-helpers.js +143 -0
  57. package/src/lib/orchestrator/internals/tx-transformer.d.ts +12 -0
  58. package/src/lib/orchestrator/internals/tx-transformer.js +120 -0
  59. package/src/lib/orchestrator/internals/uea-manager.d.ts +17 -0
  60. package/src/lib/orchestrator/internals/uea-manager.js +164 -0
  61. package/src/lib/orchestrator/orchestrator.d.ts +33 -431
  62. package/src/lib/orchestrator/orchestrator.js +124 -6125
  63. package/src/lib/orchestrator/orchestrator.types.d.ts +11 -10
  64. package/src/lib/orchestrator/payload-builders.js +34 -8
  65. package/src/lib/price-fetch/price-fetch.js +19 -7
  66. package/src/lib/push-chain/push-chain.d.ts +6 -0
  67. package/src/lib/push-chain/push-chain.js +10 -2
  68. package/src/lib/push-client/push-client.d.ts +3 -0
  69. package/src/lib/push-client/push-client.js +21 -31
  70. package/src/lib/universal/account/account.d.ts +35 -16
  71. package/src/lib/universal/account/account.js +298 -16
  72. package/src/lib/universal/signer/signer.d.ts +2 -3
  73. package/src/lib/universal/signer/signer.js +65 -115
  74. package/src/lib/universal/universal.types.d.ts +41 -0
  75. package/src/lib/utils.d.ts +7 -2
  76. package/src/lib/utils.js +65 -34
  77. package/src/lib/vm-client/evm-client.js +3 -11
  78. package/src/lib/vm-client/svm-client.d.ts +0 -4
  79. package/src/lib/vm-client/svm-client.js +2 -8
  80. package/src/index.js.map +0 -1
  81. package/src/lib/cache/cache.js.map +0 -1
  82. package/src/lib/constants/abi/cea.evm.js.map +0 -1
  83. package/src/lib/constants/abi/ceaFactory.evm.js.map +0 -1
  84. package/src/lib/constants/abi/erc20.evm.js.map +0 -1
  85. package/src/lib/constants/abi/factoryV1.js.map +0 -1
  86. package/src/lib/constants/abi/feeLocker.evm.js.map +0 -1
  87. package/src/lib/constants/abi/index.js.map +0 -1
  88. package/src/lib/constants/abi/prc20.evm.js.map +0 -1
  89. package/src/lib/constants/abi/uea-factory.js.map +0 -1
  90. package/src/lib/constants/abi/uea.evm.js.map +0 -1
  91. package/src/lib/constants/abi/uea.svm.js.map +0 -1
  92. package/src/lib/constants/abi/universalGateway.evm.js.map +0 -1
  93. package/src/lib/constants/abi/universalGatewayPC.evm.js.map +0 -1
  94. package/src/lib/constants/abi/universalGatewayV0.evm.js.map +0 -1
  95. package/src/lib/constants/chain.js.map +0 -1
  96. package/src/lib/constants/enums.js.map +0 -1
  97. package/src/lib/constants/index.js.map +0 -1
  98. package/src/lib/constants/selectors.js.map +0 -1
  99. package/src/lib/constants/tokens.js.map +0 -1
  100. package/src/lib/generated/uexecutor/v1/query.js.map +0 -1
  101. package/src/lib/generated/uexecutor/v1/types.js.map +0 -1
  102. package/src/lib/generated/uexecutor/v2/index.js.map +0 -1
  103. package/src/lib/generated/uexecutor/v2/query.js.map +0 -1
  104. package/src/lib/generated/uexecutor/v2/types.js.map +0 -1
  105. package/src/lib/generated/v1/tx.js.map +0 -1
  106. package/src/lib/index.js.map +0 -1
  107. package/src/lib/internal/buffer.js.map +0 -1
  108. package/src/lib/internal/global-buffer-polyfill.js.map +0 -1
  109. package/src/lib/orchestrator/cea-utils.js.map +0 -1
  110. package/src/lib/orchestrator/orchestrator.js.map +0 -1
  111. package/src/lib/orchestrator/orchestrator.types.js.map +0 -1
  112. package/src/lib/orchestrator/payload-builders.js.map +0 -1
  113. package/src/lib/orchestrator/route-detector.js.map +0 -1
  114. package/src/lib/price-fetch/price-fetch.js.map +0 -1
  115. package/src/lib/progress-hook/progress-hook.js.map +0 -1
  116. package/src/lib/progress-hook/progress-hook.types.js.map +0 -1
  117. package/src/lib/push-chain/helpers/abis.js.map +0 -1
  118. package/src/lib/push-chain/helpers/addresses.js.map +0 -1
  119. package/src/lib/push-chain/push-chain.js.map +0 -1
  120. package/src/lib/push-client/push-client.js.map +0 -1
  121. package/src/lib/push-client/push-client.types.js.map +0 -1
  122. package/src/lib/universal/account/account.js.map +0 -1
  123. package/src/lib/universal/account/index.js.map +0 -1
  124. package/src/lib/universal/signer/index.js.map +0 -1
  125. package/src/lib/universal/signer/signer.js.map +0 -1
  126. package/src/lib/universal/signer/signer.types.js.map +0 -1
  127. package/src/lib/universal/universal.types.js.map +0 -1
  128. package/src/lib/utils.js.map +0 -1
  129. package/src/lib/vm-client/evm-client.js.map +0 -1
  130. package/src/lib/vm-client/svm-client.js.map +0 -1
  131. package/src/lib/vm-client/vm-client.types.js.map +0 -1
@@ -6,12 +6,14 @@ exports.fromChainAgnostic = fromChainAgnostic;
6
6
  exports.convertOriginToExecutor = convertOriginToExecutor;
7
7
  exports.convertExecutorToOriginAccount = convertExecutorToOriginAccount;
8
8
  exports.convertExecutorToOrigin = convertExecutorToOrigin;
9
+ exports.deriveExecutorAccount = deriveExecutorAccount;
10
+ exports.resolveControllerAccount = resolveControllerAccount;
9
11
  const tslib_1 = require("tslib");
10
12
  const viem_1 = require("viem");
11
13
  const chain_1 = require("../../constants/chain");
12
14
  const enums_1 = require("../../constants/enums");
13
- const anchor_1 = require("@coral-xyz/anchor");
14
- const abi_1 = require("../../constants/abi");
15
+ const bs58_1 = require("../../internal/bs58");
16
+ const factoryV1_1 = require("../../constants/abi/factoryV1");
15
17
  const push_client_1 = require("../../push-client/push-client");
16
18
  const cache_1 = require("../../cache/cache");
17
19
  const push_chain_1 = require("../../push-chain/push-chain");
@@ -120,6 +122,9 @@ function fromChainAgnostic(caip) {
120
122
  }
121
123
  // Global cache instance for convertOriginToExecutor
122
124
  const accountCache = new cache_1.Cache();
125
+ // Cache for convertExecutorToOrigin — UEA→origin mapping is immutable once deployed.
126
+ // Keyed by `${address}:${network}` to handle different Push Chain networks.
127
+ const executorToOriginCache = new Map();
123
128
  /**
124
129
  * Determines the Push Network based on the chain type (testnet vs mainnet)
125
130
  */
@@ -154,8 +159,17 @@ function getPushNetworkFromChain(chain) {
154
159
  throw new Error(`Unsupported chain for Push Network mapping: ${chain}`);
155
160
  }
156
161
  }
162
+ let _convertOriginToExecutorWarned = false;
163
+ /**
164
+ * @deprecated Use `deriveExecutorAccount()` instead, which accepts a CAIP-10
165
+ * string and uses `options.chain` to control UEA vs CEA derivation.
166
+ */
157
167
  function convertOriginToExecutor(account_1) {
158
168
  return tslib_1.__awaiter(this, arguments, void 0, function* (account, options = { onlyCompute: true }) {
169
+ if (!_convertOriginToExecutorWarned) {
170
+ console.warn('[PushChain] convertOriginToExecutor() is deprecated. Use deriveExecutorAccount() instead.');
171
+ _convertOriginToExecutorWarned = true;
172
+ }
159
173
  const { chain, address } = account;
160
174
  const { vm, chainId } = chain_1.CHAIN_INFO[chain];
161
175
  // If target chain is external, compute CEA on that chain
@@ -222,7 +236,7 @@ function convertOriginToExecutor(account_1) {
222
236
  });
223
237
  const computedAddress = yield pushClient.readContract({
224
238
  address: pushClient.pushChainInfo.factoryAddress,
225
- abi: abi_1.FACTORY_V1,
239
+ abi: factoryV1_1.FACTORY_V1,
226
240
  functionName: 'computeUEA',
227
241
  args: [
228
242
  {
@@ -237,7 +251,7 @@ function convertOriginToExecutor(account_1) {
237
251
  owner: vm === enums_1.VM.EVM
238
252
  ? address
239
253
  : vm === enums_1.VM.SVM
240
- ? (0, viem_1.bytesToHex)(Uint8Array.from(anchor_1.utils.bytes.bs58.decode(address)))
254
+ ? (0, viem_1.bytesToHex)(Uint8Array.from(bs58_1.bs58.decode(address)))
241
255
  : address,
242
256
  },
243
257
  ],
@@ -265,18 +279,24 @@ function convertOriginToExecutor(account_1) {
265
279
  * @deprecated Use `convertExecutorToOrigin()` instead, which supports both
266
280
  * UEA and CEA lookups via the optional `options.chain` parameter.
267
281
  */
268
- function convertExecutorToOriginAccount(ueaAddress) {
282
+ let _convertExecutorToOriginAccountWarned = false;
283
+ function convertExecutorToOriginAccount(ueaAddress, options) {
269
284
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
270
- console.warn('[PushChain] convertExecutorToOriginAccount() is deprecated. Use convertExecutorToOrigin() instead.');
271
- const RPC_URL = chain_1.PUSH_CHAIN_INFO[enums_1.CHAIN.PUSH_TESTNET_DONUT].defaultRPC[0];
272
- const FACTORY_ADDRESS = chain_1.PUSH_CHAIN_INFO[enums_1.CHAIN.PUSH_TESTNET_DONUT].factoryAddress;
285
+ var _a;
286
+ if (!_convertExecutorToOriginAccountWarned) {
287
+ console.warn('[PushChain] convertExecutorToOriginAccount() is deprecated. Use resolveControllerAccount() instead.');
288
+ _convertExecutorToOriginAccountWarned = true;
289
+ }
290
+ const pushChainKey = pushNetworkToChainKey((_a = options === null || options === void 0 ? void 0 : options.network) !== null && _a !== void 0 ? _a : enums_1.PUSH_NETWORK.TESTNET_DONUT);
291
+ const RPC_URL = chain_1.PUSH_CHAIN_INFO[pushChainKey].defaultRPC[0];
292
+ const FACTORY_ADDRESS = chain_1.PUSH_CHAIN_INFO[pushChainKey].factoryAddress;
273
293
  // Create viem public client
274
294
  const client = (0, viem_1.createPublicClient)({
275
295
  transport: (0, viem_1.http)(RPC_URL),
276
296
  });
277
297
  const originResult = (yield client.readContract({
278
298
  address: FACTORY_ADDRESS,
279
- abi: abi_1.FACTORY_V1,
299
+ abi: factoryV1_1.FACTORY_V1,
280
300
  functionName: 'getOriginForUEA',
281
301
  args: [ueaAddress],
282
302
  }));
@@ -291,7 +311,7 @@ function convertExecutorToOriginAccount(ueaAddress) {
291
311
  if (universalAccount.chain.startsWith(chain_1.VM_NAMESPACE[enums_1.VM.SVM])) {
292
312
  // Convert hex-encoded owner to base58 address format
293
313
  const hexBytes = (0, viem_1.hexToBytes)(account.owner);
294
- universalAccount.address = anchor_1.utils.bytes.bs58.encode(hexBytes);
314
+ universalAccount.address = bs58_1.bs58.encode(Buffer.from(hexBytes));
295
315
  }
296
316
  }
297
317
  return { account: universalAccount, exists: isUEA };
@@ -304,9 +324,18 @@ function convertExecutorToOriginAccount(ueaAddress) {
304
324
  * the mapped origin account (same as convertExecutorToOriginAccount).
305
325
  * - With `chain`: treats the address as a CEA on the specified external chain,
306
326
  * looks up the corresponding PushAccount (UEA) on Push Chain, and returns it.
327
+ *
328
+ * @deprecated Use `resolveControllerAccount()` instead, which accepts a CAIP-10
329
+ * string and supports both UEA and CEA lookups via `options.chain`.
307
330
  */
331
+ let _convertExecutorToOriginWarned = false;
308
332
  function convertExecutorToOrigin(executorAddress, options) {
309
333
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
334
+ var _a;
335
+ if (!(options === null || options === void 0 ? void 0 : options._internal) && !_convertExecutorToOriginWarned) {
336
+ console.warn('[PushChain] convertExecutorToOrigin() is deprecated. Use resolveControllerAccount() instead.');
337
+ _convertExecutorToOriginWarned = true;
338
+ }
310
339
  if ((options === null || options === void 0 ? void 0 : options.chain) && !isPushChain(options.chain)) {
311
340
  // CEA on external chain → look up PushAccount (UEA) on Push Chain
312
341
  const pushAccountAddress = yield (0, cea_utils_1.getPushAccountForCEA)(executorAddress, options.chain);
@@ -336,14 +365,21 @@ function convertExecutorToOrigin(executorAddress, options) {
336
365
  };
337
366
  }
338
367
  // Default: UEA on Push Chain → origin account
339
- const RPC_URL = chain_1.PUSH_CHAIN_INFO[enums_1.CHAIN.PUSH_TESTNET_DONUT].defaultRPC[0];
340
- const FACTORY_ADDRESS = chain_1.PUSH_CHAIN_INFO[enums_1.CHAIN.PUSH_TESTNET_DONUT].factoryAddress;
368
+ const network = (_a = options === null || options === void 0 ? void 0 : options.network) !== null && _a !== void 0 ? _a : enums_1.PUSH_NETWORK.TESTNET_DONUT;
369
+ const cacheKey = `${executorAddress.toLowerCase()}:${network}`;
370
+ const cached = executorToOriginCache.get(cacheKey);
371
+ if (cached) {
372
+ return cached;
373
+ }
374
+ const pushChainKey = pushNetworkToChainKey(network);
375
+ const RPC_URL = chain_1.PUSH_CHAIN_INFO[pushChainKey].defaultRPC[0];
376
+ const FACTORY_ADDRESS = chain_1.PUSH_CHAIN_INFO[pushChainKey].factoryAddress;
341
377
  const client = (0, viem_1.createPublicClient)({
342
378
  transport: (0, viem_1.http)(RPC_URL),
343
379
  });
344
380
  const originResult = (yield client.readContract({
345
381
  address: FACTORY_ADDRESS,
346
- abi: abi_1.FACTORY_V1,
382
+ abi: factoryV1_1.FACTORY_V1,
347
383
  functionName: 'getOriginForUEA',
348
384
  args: [executorAddress],
349
385
  }));
@@ -351,21 +387,267 @@ function convertExecutorToOrigin(executorAddress, options) {
351
387
  if (account.chainNamespace === '' ||
352
388
  account.chainId === '' ||
353
389
  account.owner === '0x') {
354
- return { account: null, exists: isUEA };
390
+ const result = { account: null, exists: isUEA };
391
+ executorToOriginCache.set(cacheKey, result);
392
+ return result;
355
393
  }
356
394
  const universalAccount = push_chain_1.PushChain.utils.account.fromChainAgnostic(`${account.chainNamespace}:${account.chainId}:${account.owner}`);
357
395
  if (isUEA) {
358
396
  if (universalAccount.chain.startsWith(chain_1.VM_NAMESPACE[enums_1.VM.SVM])) {
359
397
  const hexBytes = (0, viem_1.hexToBytes)(account.owner);
360
- universalAccount.address = anchor_1.utils.bytes.bs58.encode(hexBytes);
398
+ universalAccount.address = bs58_1.bs58.encode(Buffer.from(hexBytes));
361
399
  }
362
400
  }
363
- return { account: universalAccount, exists: isUEA };
401
+ const result = { account: universalAccount, exists: isUEA };
402
+ executorToOriginCache.set(cacheKey, result);
403
+ return result;
364
404
  });
365
405
  }
406
+ /**
407
+ * Maps a PUSH_NETWORK to the corresponding Push Chain key for PUSH_CHAIN_INFO lookup.
408
+ */
409
+ function pushNetworkToChainKey(network) {
410
+ if (network === enums_1.PUSH_NETWORK.MAINNET)
411
+ return enums_1.CHAIN.PUSH_MAINNET;
412
+ if (network === enums_1.PUSH_NETWORK.TESTNET_DONUT || network === enums_1.PUSH_NETWORK.TESTNET)
413
+ return enums_1.CHAIN.PUSH_TESTNET_DONUT;
414
+ return enums_1.CHAIN.PUSH_LOCALNET;
415
+ }
366
416
  function isPushChain(chain) {
367
417
  return (chain === enums_1.CHAIN.PUSH_MAINNET ||
368
418
  chain === enums_1.CHAIN.PUSH_TESTNET_DONUT ||
369
419
  chain === enums_1.CHAIN.PUSH_LOCALNET);
370
420
  }
421
+ /**
422
+ * Resolves the chain name (enum key) for a CHAIN value.
423
+ * e.g., CHAIN.PUSH_TESTNET_DONUT → "PUSH_TESTNET_DONUT"
424
+ */
425
+ function getChainName(chain) {
426
+ // Special case: prefer PUSH_TESTNET_DONUT over PUSH_TESTNET for 'eip155:42101'
427
+ if (chain === 'eip155:42101') {
428
+ return 'PUSH_TESTNET_DONUT';
429
+ }
430
+ const entry = Object.entries(enums_1.CHAIN).find(([, val]) => val === chain);
431
+ return entry ? entry[0] : chain;
432
+ }
433
+ /**
434
+ * Derive the executor account (UEA or CEA) for a given origin account.
435
+ *
436
+ * @param account - CAIP-10 formatted address string (e.g., "eip155:11155111:0xABC...")
437
+ * @param options.chain - Target chain for CEA derivation. If omitted, derives UEA on Push Chain.
438
+ * @param options.skipNetworkCheck - If true, skip deployment check and return deployed: false.
439
+ * @returns The derived executor account address and deployment status.
440
+ */
441
+ function deriveExecutorAccount(account, options) {
442
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
443
+ var _a;
444
+ const { chain: originChain, address } = fromChainAgnostic(account);
445
+ const skipNetworkCheck = (_a = options === null || options === void 0 ? void 0 : options.skipNetworkCheck) !== null && _a !== void 0 ? _a : false;
446
+ const targetChain = options === null || options === void 0 ? void 0 : options.chain;
447
+ // If target chain is external, derive CEA on that chain
448
+ if (targetChain && !isPushChain(targetChain)) {
449
+ // First get the UEA on Push Chain
450
+ let ueaAddress;
451
+ if (isPushChain(originChain)) {
452
+ ueaAddress = address;
453
+ }
454
+ else {
455
+ const ueaResult = yield deriveExecutorAccount(account);
456
+ ueaAddress = ueaResult.address;
457
+ }
458
+ // Get CEA on the target external chain
459
+ const { cea, isDeployed } = yield (0, cea_utils_1.getCEAAddress)(ueaAddress, targetChain);
460
+ return { address: cea, deployed: skipNetworkCheck ? false : isDeployed };
461
+ }
462
+ // If origin is Push chain, return the address directly
463
+ if (isPushChain(originChain)) {
464
+ if (skipNetworkCheck) {
465
+ return { address: address, deployed: false };
466
+ }
467
+ const pushNetwork = getPushNetworkFromChain(originChain);
468
+ const pushChainKey = pushNetworkToChainKey(pushNetwork);
469
+ const pushClient = new push_client_1.PushClient({
470
+ rpcUrls: chain_1.CHAIN_INFO[pushChainKey].defaultRPC,
471
+ network: pushNetwork,
472
+ });
473
+ const byteCode = yield pushClient.publicClient.getCode({
474
+ address: address,
475
+ });
476
+ return { address: address, deployed: byteCode !== undefined };
477
+ }
478
+ // Origin is external chain → compute UEA on Push Chain
479
+ const { vm, chainId } = chain_1.CHAIN_INFO[originChain];
480
+ const pushNetwork = getPushNetworkFromChain(originChain);
481
+ // Check cache
482
+ const cachedAddress = accountCache.get(cache_1.CacheKeys.ueaAddressOnchain(originChain, address, pushNetwork, vm));
483
+ if (cachedAddress) {
484
+ if (skipNetworkCheck) {
485
+ return { address: cachedAddress, deployed: false };
486
+ }
487
+ const cachedDeploymentStatus = accountCache.get(cache_1.CacheKeys.deploymentStatus(cachedAddress));
488
+ if (cachedDeploymentStatus !== null) {
489
+ return {
490
+ address: cachedAddress,
491
+ deployed: cachedDeploymentStatus,
492
+ };
493
+ }
494
+ }
495
+ const pushChainKey = pushNetworkToChainKey(pushNetwork);
496
+ const pushClient = new push_client_1.PushClient({
497
+ rpcUrls: chain_1.CHAIN_INFO[pushChainKey].defaultRPC,
498
+ network: pushNetwork,
499
+ });
500
+ const computedAddress = yield pushClient.readContract({
501
+ address: pushClient.pushChainInfo.factoryAddress,
502
+ abi: factoryV1_1.FACTORY_V1,
503
+ functionName: 'computeUEA',
504
+ args: [
505
+ {
506
+ chainNamespace: chain_1.VM_NAMESPACE[vm],
507
+ chainId: chainId,
508
+ owner: vm === enums_1.VM.EVM
509
+ ? address
510
+ : vm === enums_1.VM.SVM
511
+ ? (0, viem_1.bytesToHex)(Uint8Array.from(bs58_1.bs58.decode(address)))
512
+ : address,
513
+ },
514
+ ],
515
+ });
516
+ // Cache the computed address
517
+ accountCache.set(cache_1.CacheKeys.ueaAddressOnchain(originChain, address, pushNetwork, vm), computedAddress);
518
+ if (skipNetworkCheck) {
519
+ return { address: computedAddress, deployed: false };
520
+ }
521
+ const byteCode = yield pushClient.publicClient.getCode({
522
+ address: computedAddress,
523
+ });
524
+ const isDeployed = byteCode !== undefined;
525
+ // Cache the deployment status
526
+ accountCache.set(cache_1.CacheKeys.deploymentStatus(computedAddress), isDeployed);
527
+ return { address: computedAddress, deployed: isDeployed };
528
+ });
529
+ }
530
+ /**
531
+ * Resolve the controller (origin) accounts for a given executor address.
532
+ *
533
+ * Given a UEA or CEA address (as CAIP-10), resolves the full controller chain
534
+ * back to the origin account.
535
+ *
536
+ * @param account - CAIP-10 formatted address string of the executor account
537
+ * @param options.chain - Supplementary chain context (chain info is in CAIP-10)
538
+ * @param options.skipNetworkCheck - If true, skip existence checks, set exists: false
539
+ * @returns Resolved accounts in the controller chain
540
+ */
541
+ function resolveControllerAccount(account, options) {
542
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
543
+ var _a;
544
+ const { chain: inputChain, address } = fromChainAgnostic(account);
545
+ const skipNetworkCheck = (_a = options === null || options === void 0 ? void 0 : options.skipNetworkCheck) !== null && _a !== void 0 ? _a : false;
546
+ // Case A: Input is on an external chain (CEA)
547
+ if (!isPushChain(inputChain)) {
548
+ // Look up UEA on Push Chain from CEA
549
+ const pushAccountAddress = yield (0, cea_utils_1.getPushAccountForCEA)(address, inputChain);
550
+ if (pushAccountAddress === '0x0000000000000000000000000000000000000000') {
551
+ return { accounts: [] };
552
+ }
553
+ // Determine Push Chain from external chain's network
554
+ const pushNetwork = getPushNetworkFromChain(inputChain);
555
+ const pushChainKey = pushNetworkToChainKey(pushNetwork);
556
+ // Now resolve UEA → origin
557
+ const pushChainId = pushChainKey;
558
+ const RPC_URL = chain_1.PUSH_CHAIN_INFO[pushChainKey].defaultRPC[0];
559
+ const FACTORY_ADDRESS = chain_1.PUSH_CHAIN_INFO[pushChainKey].factoryAddress;
560
+ const client = (0, viem_1.createPublicClient)({ transport: (0, viem_1.http)(RPC_URL) });
561
+ const originResult = (yield client.readContract({
562
+ address: FACTORY_ADDRESS,
563
+ abi: factoryV1_1.FACTORY_V1,
564
+ functionName: 'getOriginForUEA',
565
+ args: [pushAccountAddress],
566
+ }));
567
+ const [originAccount, isUEA] = originResult;
568
+ const accounts = [];
569
+ // Add UEA entry
570
+ accounts.push({
571
+ chain: pushChainId,
572
+ chainName: getChainName(pushChainId),
573
+ address: pushAccountAddress,
574
+ type: 'uea',
575
+ exists: skipNetworkCheck ? false : true,
576
+ });
577
+ // Add origin (UOA) entry if found
578
+ if (isUEA &&
579
+ originAccount.chainNamespace !== '' &&
580
+ originAccount.chainId !== '' &&
581
+ originAccount.owner !== '0x') {
582
+ const originUniversal = fromChainAgnostic(`${originAccount.chainNamespace}:${originAccount.chainId}:${originAccount.owner}`);
583
+ // Handle SVM address conversion
584
+ let originAddress = originUniversal.address;
585
+ if (originUniversal.chain.startsWith(chain_1.VM_NAMESPACE[enums_1.VM.SVM])) {
586
+ const hexBytes = (0, viem_1.hexToBytes)(originAccount.owner);
587
+ originAddress = bs58_1.bs58.encode(Buffer.from(hexBytes));
588
+ }
589
+ accounts.push({
590
+ chain: originUniversal.chain,
591
+ chainName: getChainName(originUniversal.chain),
592
+ address: originAddress,
593
+ type: 'uoa',
594
+ exists: skipNetworkCheck ? false : true,
595
+ role: 'controller',
596
+ });
597
+ }
598
+ return { accounts };
599
+ }
600
+ // Case B: Input is on Push Chain (UEA or EOA)
601
+ const pushNetwork = getPushNetworkFromChain(inputChain);
602
+ const pushChainKey = pushNetworkToChainKey(pushNetwork);
603
+ const RPC_URL = chain_1.PUSH_CHAIN_INFO[pushChainKey].defaultRPC[0];
604
+ const FACTORY_ADDRESS = chain_1.PUSH_CHAIN_INFO[pushChainKey].factoryAddress;
605
+ const client = (0, viem_1.createPublicClient)({ transport: (0, viem_1.http)(RPC_URL) });
606
+ const originResult = (yield client.readContract({
607
+ address: FACTORY_ADDRESS,
608
+ abi: factoryV1_1.FACTORY_V1,
609
+ functionName: 'getOriginForUEA',
610
+ args: [address],
611
+ }));
612
+ const [originAccount, isUEA] = originResult;
613
+ // If it's a UEA, resolve to origin
614
+ if (isUEA &&
615
+ originAccount.chainNamespace !== '' &&
616
+ originAccount.chainId !== '' &&
617
+ originAccount.owner !== '0x') {
618
+ const originUniversal = fromChainAgnostic(`${originAccount.chainNamespace}:${originAccount.chainId}:${originAccount.owner}`);
619
+ // Handle SVM address conversion
620
+ let originAddress = originUniversal.address;
621
+ if (originUniversal.chain.startsWith(chain_1.VM_NAMESPACE[enums_1.VM.SVM])) {
622
+ const hexBytes = (0, viem_1.hexToBytes)(originAccount.owner);
623
+ originAddress = bs58_1.bs58.encode(Buffer.from(hexBytes));
624
+ }
625
+ return {
626
+ accounts: [
627
+ {
628
+ chain: originUniversal.chain,
629
+ chainName: getChainName(originUniversal.chain),
630
+ address: originAddress,
631
+ type: 'uoa',
632
+ exists: skipNetworkCheck ? false : true,
633
+ role: 'controller',
634
+ },
635
+ ],
636
+ };
637
+ }
638
+ // Not a UEA — Push Chain EOA/smart contract, return as controller
639
+ return {
640
+ accounts: [
641
+ {
642
+ chain: inputChain,
643
+ chainName: getChainName(inputChain),
644
+ address: address,
645
+ type: 'uoa',
646
+ exists: skipNetworkCheck ? false : true,
647
+ role: 'controller',
648
+ },
649
+ ],
650
+ };
651
+ });
652
+ }
371
653
  //# sourceMappingURL=account.js.map
@@ -3,7 +3,6 @@ import { TypedDataDomain, TypedData } from '../../constants';
3
3
  import { EthersV5SignerType, EthersV6SignerType, UniversalAccount, UniversalSigner, UniversalSignerSkeleton, ViemSignerType } from '../universal.types';
4
4
  import { Keypair } from '@solana/web3.js';
5
5
  import { CHAIN, LIBRARY } from '../../constants/enums';
6
- import { ethers } from 'ethers';
7
6
  /**
8
7
  * Creates a `UniversalSigner` object for signing messages and transactions
9
8
  * on any supported chain.
@@ -27,11 +26,11 @@ export declare function createUniversalSigner({ account, signMessage, signAndSen
27
26
  /**
28
27
  * Creates a UniversalSigner from either a viem, ethers, solana WalletClient or Account instance.
29
28
  *
30
- * @param {WalletClient | Account | Keypair | ethers.HDNodeWallet} clientOrAccount - The viem WalletClient or Account instance
29
+ * @param {WalletClient | Account | Keypair} clientOrAccount - The viem WalletClient or Account instance
31
30
  * @param {CHAIN} chain - The chain the signer will operate on
32
31
  * @returns {Promise<UniversalSigner>} A signer object configured for the specified chain
33
32
  */
34
- export declare function toUniversalFromKeypair(clientOrAccount: WalletClient | Keypair | ethers.Wallet | ethers.HDNodeWallet, { chain, library }: {
33
+ export declare function toUniversalFromKeypair(clientOrAccount: WalletClient | Keypair | EthersV6SignerType, { chain, library }: {
35
34
  chain: CHAIN;
36
35
  library: LIBRARY;
37
36
  }): Promise<UniversalSigner>;