@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,53 @@ exports.construct = construct;
6
6
  exports.toUniversal = toUniversal;
7
7
  const tslib_1 = require("tslib");
8
8
  const viem_1 = require("viem");
9
- const nacl = tslib_1.__importStar(require("tweetnacl"));
9
+ let _nacl = null;
10
+ function getNacl() {
11
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
12
+ if (!_nacl)
13
+ _nacl = yield Promise.resolve().then(() => tslib_1.__importStar(require('tweetnacl')));
14
+ return _nacl;
15
+ });
16
+ }
10
17
  const web3_js_1 = require("@solana/web3.js");
11
18
  const enums_1 = require("../../constants/enums");
12
- const ethers_1 = require("ethers");
13
19
  const chain_1 = require("../../constants/chain");
14
- const anchor_1 = require("@coral-xyz/anchor");
20
+ const bs58_1 = require("../../internal/bs58");
21
+ /**
22
+ * Converts viem's parsed transaction to an ethers-compatible TransactionRequest.
23
+ * viem uses `gas` while ethers expects `gasLimit`.
24
+ */
25
+ function toEthersTxRequest(viemTx) {
26
+ const _a = viemTx, { gas } = _a, rest = tslib_1.__rest(_a, ["gas"]);
27
+ return Object.assign(Object.assign({}, rest), { gasLimit: gas });
28
+ }
29
+ /**
30
+ * Maps an EVM numeric chainId to the corresponding CHAIN enum.
31
+ * Shared by all signer skeleton generators to avoid duplication.
32
+ */
33
+ function chainIdToChain(chainId) {
34
+ const id = chainId.toString();
35
+ switch (id) {
36
+ case '11155111':
37
+ return enums_1.CHAIN.ETHEREUM_SEPOLIA;
38
+ case '421614':
39
+ return enums_1.CHAIN.ARBITRUM_SEPOLIA;
40
+ case '84532':
41
+ return enums_1.CHAIN.BASE_SEPOLIA;
42
+ case '97':
43
+ return enums_1.CHAIN.BNB_TESTNET;
44
+ case '1':
45
+ return enums_1.CHAIN.ETHEREUM_MAINNET;
46
+ case '9':
47
+ return enums_1.CHAIN.PUSH_MAINNET;
48
+ case '42101':
49
+ return enums_1.CHAIN.PUSH_TESTNET;
50
+ case '9000':
51
+ return enums_1.CHAIN.PUSH_LOCALNET;
52
+ default:
53
+ throw new Error(`Unsupported chainId: ${chainId}`);
54
+ }
55
+ }
15
56
  /**
16
57
  * Creates a `UniversalSigner` object for signing messages and transactions
17
58
  * on any supported chain.
@@ -42,7 +83,7 @@ function createUniversalSigner({ account, signMessage, signAndSendTransaction, s
42
83
  /**
43
84
  * Creates a UniversalSigner from either a viem, ethers, solana WalletClient or Account instance.
44
85
  *
45
- * @param {WalletClient | Account | Keypair | ethers.HDNodeWallet} clientOrAccount - The viem WalletClient or Account instance
86
+ * @param {WalletClient | Account | Keypair} clientOrAccount - The viem WalletClient or Account instance
46
87
  * @param {CHAIN} chain - The chain the signer will operate on
47
88
  * @returns {Promise<UniversalSigner>} A signer object configured for the specified chain
48
89
  */
@@ -71,22 +112,22 @@ function toUniversalFromKeypair(clientOrAccount_1, _a) {
71
112
  throw new Error(`Chain mismatch: wallet is on ${chainId}, expected ${chain}`);
72
113
  }
73
114
  address = yield wallet.getAddress();
74
- // raw bytes → ethers.signMessage → hex → back to bytes
115
+ // raw bytes → signMessage → hex → back to bytes
75
116
  signMessage = (data) => tslib_1.__awaiter(this, void 0, void 0, function* () {
76
117
  const sigHex = yield wallet.signMessage(data);
77
- return (0, ethers_1.getBytes)(sigHex);
118
+ return (0, viem_1.hexToBytes)(sigHex);
78
119
  });
79
120
  // raw unsigned tx bytes → hex → parse → signAndSendTransaction → bytes
80
121
  signAndSendTransaction = (raw) => tslib_1.__awaiter(this, void 0, void 0, function* () {
81
- const unsignedHex = (0, ethers_1.hexlify)(raw);
82
- const tx = ethers_1.ethers.Transaction.from(unsignedHex);
122
+ const unsignedHex = (0, viem_1.bytesToHex)(raw);
123
+ const tx = toEthersTxRequest((0, viem_1.parseTransaction)(unsignedHex));
83
124
  const txResponse = yield wallet.sendTransaction(tx);
84
125
  return (0, viem_1.hexToBytes)(txResponse.hash);
85
126
  });
86
- // EIP-712 typed data → _signTypedData → hex → bytes
127
+ // EIP-712 typed data → signTypedData → hex → bytes
87
128
  signTypedData = (_a) => tslib_1.__awaiter(this, [_a], void 0, function* ({ domain, types, primaryType, message }) {
88
129
  const sigHex = yield wallet.signTypedData(domain, types, message);
89
- return (0, ethers_1.getBytes)(sigHex);
130
+ return (0, viem_1.hexToBytes)(sigHex);
90
131
  });
91
132
  break;
92
133
  }
@@ -127,6 +168,7 @@ function toUniversalFromKeypair(clientOrAccount_1, _a) {
127
168
  }
128
169
  address = keypair.publicKey.toBase58();
129
170
  signMessage = (data) => tslib_1.__awaiter(this, void 0, void 0, function* () {
171
+ const nacl = yield getNacl();
130
172
  return nacl.sign.detached(data, keypair.secretKey);
131
173
  });
132
174
  // ✅ Sign and send the transaction to Solana network
@@ -158,12 +200,13 @@ function toUniversalFromKeypair(clientOrAccount_1, _a) {
158
200
  // Handle as legacy transaction
159
201
  const tx = web3_js_1.Transaction.from(unsignedTx);
160
202
  const messageBytes = tx.serializeMessage();
203
+ const nacl = yield getNacl();
161
204
  const signature = nacl.sign.detached(messageBytes, keypair.secretKey);
162
205
  tx.addSignature(new web3_js_1.PublicKey(keypair.publicKey.toBase58()), Buffer.from(signature));
163
206
  const rawTx = tx.serialize();
164
207
  txHash = yield connection.sendRawTransaction(rawTx);
165
208
  }
166
- return anchor_1.utils.bytes.bs58.decode(txHash);
209
+ return bs58_1.bs58.decode(txHash);
167
210
  });
168
211
  signTypedData = () => tslib_1.__awaiter(this, void 0, void 0, function* () {
169
212
  throw new Error('Typed data signing is not supported for Solana');
@@ -232,56 +275,24 @@ function generateSkeletonFromEthersV5(signer) {
232
275
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
233
276
  const address = yield signer.getAddress();
234
277
  const { chainId } = yield signer.provider.getNetwork();
235
- // Map chainId to CHAIN enum - this is a simplified mapping
236
- let chain;
237
- switch (chainId.toString()) {
238
- case '11155111':
239
- chain = enums_1.CHAIN.ETHEREUM_SEPOLIA;
240
- break;
241
- case '421614':
242
- chain = enums_1.CHAIN.ARBITRUM_SEPOLIA;
243
- break;
244
- case '84532':
245
- chain = enums_1.CHAIN.BASE_SEPOLIA;
246
- break;
247
- case '97':
248
- chain = enums_1.CHAIN.BNB_TESTNET;
249
- break;
250
- case '1':
251
- chain = enums_1.CHAIN.ETHEREUM_MAINNET;
252
- break;
253
- case '9':
254
- chain = enums_1.CHAIN.PUSH_MAINNET;
255
- break;
256
- case '42101':
257
- chain = enums_1.CHAIN.PUSH_TESTNET;
258
- break;
259
- case '9000':
260
- chain = enums_1.CHAIN.PUSH_LOCALNET;
261
- break;
262
- default:
263
- throw new Error(`Unsupported chainId: ${chainId}`);
264
- }
265
- if (!Object.values(enums_1.CHAIN).includes(chain)) {
266
- throw new Error(`Unsupported chainId: ${chainId}`);
267
- }
278
+ const chain = chainIdToChain(chainId);
268
279
  return {
269
280
  signerId: `EthersSignerV5-${address}`,
270
281
  account: { address, chain },
271
282
  signMessage: (data) => tslib_1.__awaiter(this, void 0, void 0, function* () {
272
283
  const sigHex = yield signer.signMessage(data);
273
- return (0, ethers_1.getBytes)(sigHex);
284
+ return (0, viem_1.hexToBytes)(sigHex);
274
285
  }),
275
286
  // raw unsigned tx bytes → hex → parse → signTransaction → bytes
276
287
  signAndSendTransaction: (raw) => tslib_1.__awaiter(this, void 0, void 0, function* () {
277
- const unsignedHex = (0, ethers_1.hexlify)(raw);
278
- const tx = ethers_1.ethers.Transaction.from(unsignedHex);
288
+ const unsignedHex = (0, viem_1.bytesToHex)(raw);
289
+ const tx = toEthersTxRequest((0, viem_1.parseTransaction)(unsignedHex));
279
290
  const txResponse = yield signer.sendTransaction(tx);
280
291
  return (0, viem_1.hexToBytes)(txResponse.hash);
281
292
  }),
282
293
  signTypedData: (_a) => tslib_1.__awaiter(this, [_a], void 0, function* ({ domain, types, primaryType, message }) {
283
294
  const sigHex = yield signer._signTypedData(domain, types, message);
284
- return (0, ethers_1.getBytes)(sigHex);
295
+ return (0, viem_1.hexToBytes)(sigHex);
285
296
  }),
286
297
  };
287
298
  });
@@ -290,56 +301,24 @@ function generateSkeletonFromEthersV6(signer) {
290
301
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
291
302
  const address = yield signer.getAddress();
292
303
  const { chainId } = yield signer.provider.getNetwork();
293
- // Map chainId to CHAIN enum - this is a simplified mapping
294
- let chain;
295
- switch (chainId.toString()) {
296
- case '11155111':
297
- chain = enums_1.CHAIN.ETHEREUM_SEPOLIA;
298
- break;
299
- case '421614':
300
- chain = enums_1.CHAIN.ARBITRUM_SEPOLIA;
301
- break;
302
- case '84532':
303
- chain = enums_1.CHAIN.BASE_SEPOLIA;
304
- break;
305
- case '97':
306
- chain = enums_1.CHAIN.BNB_TESTNET;
307
- break;
308
- case '1':
309
- chain = enums_1.CHAIN.ETHEREUM_MAINNET;
310
- break;
311
- case '9':
312
- chain = enums_1.CHAIN.PUSH_MAINNET;
313
- break;
314
- case '42101':
315
- chain = enums_1.CHAIN.PUSH_TESTNET;
316
- break;
317
- case '9000':
318
- chain = enums_1.CHAIN.PUSH_LOCALNET;
319
- break;
320
- default:
321
- throw new Error(`Unsupported chainId: ${chainId}`);
322
- }
323
- if (!Object.values(enums_1.CHAIN).includes(chain)) {
324
- throw new Error(`Unsupported chainId: ${chainId}`);
325
- }
304
+ const chain = chainIdToChain(chainId);
326
305
  return {
327
306
  signerId: `EthersSignerV6-${address}`,
328
307
  account: { address, chain },
329
308
  signMessage: (data) => tslib_1.__awaiter(this, void 0, void 0, function* () {
330
309
  const sigHex = yield signer.signMessage(data);
331
- return (0, ethers_1.getBytes)(sigHex);
310
+ return (0, viem_1.hexToBytes)(sigHex);
332
311
  }),
333
312
  // raw unsigned tx bytes → hex → parse → signTransaction → bytes
334
313
  signAndSendTransaction: (raw) => tslib_1.__awaiter(this, void 0, void 0, function* () {
335
- const unsignedHex = (0, ethers_1.hexlify)(raw);
336
- const tx = ethers_1.ethers.Transaction.from(unsignedHex);
314
+ const unsignedHex = (0, viem_1.bytesToHex)(raw);
315
+ const tx = toEthersTxRequest((0, viem_1.parseTransaction)(unsignedHex));
337
316
  const txResponse = yield signer.sendTransaction(tx);
338
317
  return (0, viem_1.hexToBytes)(txResponse.hash);
339
318
  }),
340
319
  signTypedData: (_a) => tslib_1.__awaiter(this, [_a], void 0, function* ({ domain, types, primaryType, message }) {
341
320
  const sigHex = yield signer.signTypedData(domain, types, message);
342
- return (0, ethers_1.getBytes)(sigHex);
321
+ return (0, viem_1.hexToBytes)(sigHex);
343
322
  }),
344
323
  };
345
324
  });
@@ -355,36 +334,7 @@ function generateSkeletonFromViem(signer) {
355
334
  }
356
335
  const address = signer.account['address'];
357
336
  const chainId = yield signer.getChainId();
358
- // Map chainId to CHAIN enum
359
- let chain;
360
- switch (chainId.toString()) {
361
- case '11155111':
362
- chain = enums_1.CHAIN.ETHEREUM_SEPOLIA;
363
- break;
364
- case '421614':
365
- chain = enums_1.CHAIN.ARBITRUM_SEPOLIA;
366
- break;
367
- case '84532':
368
- chain = enums_1.CHAIN.BASE_SEPOLIA;
369
- break;
370
- case '97':
371
- chain = enums_1.CHAIN.BNB_TESTNET;
372
- break;
373
- case '1':
374
- chain = enums_1.CHAIN.ETHEREUM_MAINNET;
375
- break;
376
- case '9':
377
- chain = enums_1.CHAIN.PUSH_MAINNET;
378
- break;
379
- case '42101':
380
- chain = enums_1.CHAIN.PUSH_TESTNET;
381
- break;
382
- case '9000':
383
- chain = enums_1.CHAIN.PUSH_LOCALNET;
384
- break;
385
- default:
386
- throw new Error(`Unsupported chainId: ${chainId}`);
387
- }
337
+ const chain = chainIdToChain(chainId);
388
338
  return {
389
339
  signerId: `ViemSigner-${address}`,
390
340
  account: {
@@ -123,3 +123,44 @@ export interface ExecutorAccountInfo {
123
123
  */
124
124
  deployed?: boolean;
125
125
  }
126
+ /**
127
+ * Account type in the Push Chain ecosystem.
128
+ */
129
+ export type AccountType = 'uea' | 'cea' | 'uoa';
130
+ /**
131
+ * Role of an account in the controller relationship.
132
+ */
133
+ export type AccountRole = 'controller';
134
+ /**
135
+ * Response from deriveExecutorAccount.
136
+ */
137
+ export interface DerivedExecutorAccount {
138
+ /** The computed executor address on Push Chain (or CEA on external chain) */
139
+ address: `0x${string}`;
140
+ /** Whether the executor account is deployed on-chain */
141
+ deployed: boolean;
142
+ }
143
+ /**
144
+ * A single resolved account entry in the resolveControllerAccount response.
145
+ */
146
+ export interface ResolvedAccount {
147
+ /** Fully qualified chain identifier (e.g., "eip155:42101") */
148
+ chain: string;
149
+ /** Human-readable chain name (e.g., "PUSH_TESTNET_DONUT") */
150
+ chainName: string;
151
+ /** The account address */
152
+ address: string;
153
+ /** Account type in the ecosystem */
154
+ type: AccountType;
155
+ /** Whether this account exists on-chain */
156
+ exists: boolean;
157
+ /** Role of this account (present only for controller accounts) */
158
+ role?: AccountRole;
159
+ }
160
+ /**
161
+ * Response from resolveControllerAccount.
162
+ */
163
+ export interface ResolvedControllerAccounts {
164
+ /** List of resolved accounts in the controller chain */
165
+ accounts: ResolvedAccount[];
166
+ }
@@ -1,4 +1,4 @@
1
- import { convertOriginToExecutor, fromChainAgnostic, convertExecutorToOriginAccount, convertExecutorToOrigin, toChainAgnostic, toUniversal } from './universal/account';
1
+ import { convertOriginToExecutor, fromChainAgnostic, convertExecutorToOriginAccount, toChainAgnostic, toUniversal, deriveExecutorAccount, resolveControllerAccount } from './universal/account';
2
2
  import { construct, toUniversal as toUniversalSigner, toUniversalFromKeypair } from './universal/signer';
3
3
  import { CHAIN, PUSH_NETWORK } from './constants/enums';
4
4
  import { type MoveableToken } from './constants/tokens';
@@ -29,7 +29,8 @@ export declare class Utils {
29
29
  fromChainAgnostic: typeof fromChainAgnostic;
30
30
  convertOriginToExecutor: typeof convertOriginToExecutor;
31
31
  convertExecutorToOriginAccount: typeof convertExecutorToOriginAccount;
32
- convertExecutorToOrigin: typeof convertExecutorToOrigin;
32
+ deriveExecutorAccount: typeof deriveExecutorAccount;
33
+ resolveControllerAccount: typeof resolveControllerAccount;
33
34
  };
34
35
  static signer: {
35
36
  /**
@@ -196,6 +197,7 @@ export declare class Utils {
196
197
  getMoveableTokens(chainOrClient?: CHAIN | PushChain): {
197
198
  tokens: Array<{
198
199
  chain: CHAIN;
200
+ chainName: string;
199
201
  symbol: string;
200
202
  decimals: number;
201
203
  address: string;
@@ -210,6 +212,7 @@ export declare class Utils {
210
212
  getPayableTokens(chainOrClient?: CHAIN | PushChain): {
211
213
  tokens: Array<{
212
214
  chain: CHAIN;
215
+ chainName: string;
213
216
  symbol: string;
214
217
  decimals: number;
215
218
  address: string;
@@ -237,6 +240,8 @@ export declare class Utils {
237
240
  getPRC20Address(token: MoveableToken | {
238
241
  chain: string;
239
242
  address: string;
243
+ }, options?: {
244
+ network?: PUSH_NETWORK;
240
245
  }): `0x${string}`;
241
246
  };
242
247
  /**
package/src/lib/utils.js CHANGED
@@ -6,7 +6,7 @@ const signer_1 = require("./universal/signer");
6
6
  const enums_1 = require("./constants/enums");
7
7
  const tokens_1 = require("./constants/tokens");
8
8
  const chain_1 = require("./constants/chain");
9
- const ethers_1 = require("ethers");
9
+ const viem_1 = require("viem");
10
10
  /**
11
11
  * @dev - THESE UTILS ARE EXPORTED TO SDK CONSUMER
12
12
  * @dev - Make sure each exported fn has good comments to help out sdk consumer
@@ -71,7 +71,8 @@ Utils.account = {
71
71
  fromChainAgnostic: account_1.fromChainAgnostic,
72
72
  convertOriginToExecutor: account_1.convertOriginToExecutor,
73
73
  convertExecutorToOriginAccount: account_1.convertExecutorToOriginAccount,
74
- convertExecutorToOrigin: account_1.convertExecutorToOrigin,
74
+ deriveExecutorAccount: account_1.deriveExecutorAccount,
75
+ resolveControllerAccount: account_1.resolveControllerAccount,
75
76
  };
76
77
  Utils.signer = {
77
78
  /**
@@ -194,13 +195,17 @@ Utils.helpers = {
194
195
  * Alias maintained for backwards compatibility. Logs a deprecation warning
195
196
  * and delegates to Utils.chains.getChainNamespace.
196
197
  */
197
- getChainName: (chainName) => {
198
- // Emit deprecation warning on every call to surface migration need
199
- // Note: Keeping message explicit for SDK consumers
200
- console.warn('[DEPRECATED] PushChain.utils.helper.getChainName is deprecated. ' +
201
- 'Use PushChain.utils.chains.getChainNamespace(chainName) instead.');
202
- return Utils.chains.getChainName(chainName);
203
- },
198
+ getChainName: (() => {
199
+ let warned = false;
200
+ return (chainName) => {
201
+ if (!warned) {
202
+ console.warn('[DEPRECATED] PushChain.utils.helper.getChainName is deprecated. ' +
203
+ 'Use PushChain.utils.chains.getChainNamespace(chainName) instead.');
204
+ warned = true;
205
+ }
206
+ return Utils.chains.getChainName(chainName);
207
+ };
208
+ })(),
204
209
  encodeTxData({ abi, functionName, args = [], }) {
205
210
  // Validate inputs
206
211
  if (!Array.isArray(abi)) {
@@ -215,9 +220,7 @@ Utils.helpers = {
215
220
  throw new Error(`Function '${functionName}' not found in ABI`);
216
221
  }
217
222
  try {
218
- // Create ethers Interface and encode the function data
219
- const abiInterface = new ethers_1.ethers.Interface(abi);
220
- const data = abiInterface.encodeFunctionData(functionName, args);
223
+ const data = (0, viem_1.encodeFunctionData)({ abi, functionName, args });
221
224
  return data;
222
225
  }
223
226
  catch (error) {
@@ -385,8 +388,12 @@ Utils.helpers = {
385
388
  try {
386
389
  // Convert string to bigint if needed
387
390
  const bigintValue = typeof value === 'string' ? BigInt(value) : value;
388
- // Use ethers to format the units
389
- const formatted = ethers_1.ethers.formatUnits(bigintValue, decimals);
391
+ let formatted = (0, viem_1.formatUnits)(bigintValue, decimals);
392
+ // Ensure at least one decimal place for backward compatibility
393
+ // (only when decimals > 0, matching prior ethers behavior)
394
+ if (decimals > 0 && !formatted.includes('.')) {
395
+ formatted = formatted + '.0';
396
+ }
390
397
  // Apply precision if specified
391
398
  if (precision !== undefined) {
392
399
  const num = parseFloat(formatted);
@@ -471,18 +478,22 @@ Utils.tokens = {
471
478
  * - Otherwise returns tokens across all chains
472
479
  */
473
480
  getMoveableTokens(chainOrClient) {
474
- var _a;
481
+ var _a, _b;
475
482
  const chain = Utils.resolveChainFromInput(chainOrClient);
476
483
  if (chain) {
477
484
  const list = (_a = tokens_1.MOVEABLE_TOKENS[chain]) !== null && _a !== void 0 ? _a : [];
478
485
  return {
479
- tokens: list.map((t) => ({
480
- chain,
481
- symbol: t.symbol,
482
- decimals: t.decimals,
483
- address: t.address,
484
- mechanism: t.mechanism,
485
- })),
486
+ tokens: list.map((t) => {
487
+ var _a;
488
+ return ({
489
+ chain,
490
+ chainName: (_a = Utils.chains.getChainName(chain)) !== null && _a !== void 0 ? _a : chain,
491
+ symbol: t.symbol,
492
+ decimals: t.decimals,
493
+ address: t.address,
494
+ mechanism: t.mechanism,
495
+ });
496
+ }),
486
497
  };
487
498
  }
488
499
  const tokens = [];
@@ -491,6 +502,7 @@ Utils.tokens = {
491
502
  for (const t of list !== null && list !== void 0 ? list : []) {
492
503
  tokens.push({
493
504
  chain: k,
505
+ chainName: (_b = Utils.chains.getChainName(k)) !== null && _b !== void 0 ? _b : k,
494
506
  symbol: t.symbol,
495
507
  decimals: t.decimals,
496
508
  address: t.address,
@@ -506,18 +518,22 @@ Utils.tokens = {
506
518
  * - Otherwise returns tokens across all chains
507
519
  */
508
520
  getPayableTokens(chainOrClient) {
509
- var _a;
521
+ var _a, _b;
510
522
  const chain = Utils.resolveChainFromInput(chainOrClient);
511
523
  if (chain) {
512
524
  const list = (_a = tokens_1.PAYABLE_TOKENS[chain]) !== null && _a !== void 0 ? _a : [];
513
525
  return {
514
- tokens: list.map((t) => ({
515
- chain,
516
- symbol: t.symbol,
517
- decimals: t.decimals,
518
- address: t.address,
519
- mechanism: t.mechanism,
520
- })),
526
+ tokens: list.map((t) => {
527
+ var _a;
528
+ return ({
529
+ chain,
530
+ chainName: (_a = Utils.chains.getChainName(chain)) !== null && _a !== void 0 ? _a : chain,
531
+ symbol: t.symbol,
532
+ decimals: t.decimals,
533
+ address: t.address,
534
+ mechanism: t.mechanism,
535
+ });
536
+ }),
521
537
  };
522
538
  }
523
539
  const tokens = [];
@@ -526,6 +542,7 @@ Utils.tokens = {
526
542
  for (const t of list !== null && list !== void 0 ? list : []) {
527
543
  tokens.push({
528
544
  chain: k,
545
+ chainName: (_b = Utils.chains.getChainName(k)) !== null && _b !== void 0 ? _b : k,
529
546
  symbol: t.symbol,
530
547
  decimals: t.decimals,
531
548
  address: t.address,
@@ -553,8 +570,8 @@ Utils.tokens = {
553
570
  * // → `0x...`
554
571
  * ```
555
572
  */
556
- getPRC20Address(token) {
557
- var _a;
573
+ getPRC20Address(token, options) {
574
+ var _a, _b;
558
575
  // Infer origin chain and symbol by matching against the MOVEABLE_TOKENS registry
559
576
  let originChain;
560
577
  let tokenSymbol;
@@ -582,8 +599,7 @@ Utils.tokens = {
582
599
  if (!originChain || !tokenSymbol) {
583
600
  throw new Error('Unable to infer origin chain or token symbol for token');
584
601
  }
585
- // Select Push network mapping (tests/use-cases use TESTNET_DONUT; identical to TESTNET here)
586
- const network = enums_1.PUSH_NETWORK.TESTNET_DONUT;
602
+ const network = (_b = options === null || options === void 0 ? void 0 : options.network) !== null && _b !== void 0 ? _b : enums_1.PUSH_NETWORK.TESTNET_DONUT;
587
603
  const map = chain_1.SYNTHETIC_PUSH_ERC20[network];
588
604
  // Map token → synthetic key by origin chain family
589
605
  const isEthFamily = originChain === enums_1.CHAIN.ETHEREUM_MAINNET ||
@@ -628,6 +644,21 @@ Utils.tokens = {
628
644
  throw new Error('Unsupported USDT origin chain for synthetic mapping');
629
645
  break;
630
646
  }
647
+ case 'USDC': {
648
+ if (isEthFamily)
649
+ key = 'USDC_ETH';
650
+ else if (isArbFamily)
651
+ key = 'USDC_ARB';
652
+ else if (isBaseFamily)
653
+ key = 'USDC_BASE';
654
+ else if (isBnbFamily)
655
+ key = 'USDC_BNB';
656
+ else if (isSolFamily)
657
+ key = 'USDC_SOL';
658
+ else
659
+ throw new Error('Unsupported USDC origin chain for synthetic mapping');
660
+ break;
661
+ }
631
662
  default:
632
663
  throw new Error(`Unsupported token symbol: ${tokenSymbol}`);
633
664
  }
@@ -85,8 +85,7 @@ class EvmClient {
85
85
  */
86
86
  getErc20Balance(_a) {
87
87
  return tslib_1.__awaiter(this, arguments, void 0, function* ({ tokenAddress, ownerAddress, }) {
88
- const { parseAbi } = yield Promise.resolve().then(() => tslib_1.__importStar(require('viem')));
89
- const erc20Abi = parseAbi([
88
+ const erc20Abi = (0, viem_1.parseAbi)([
90
89
  'function balanceOf(address) view returns (uint256)',
91
90
  ]);
92
91
  return this.readContract({
@@ -127,7 +126,7 @@ class EvmClient {
127
126
  * });
128
127
  */
129
128
  writeContract(_a) {
130
- return tslib_1.__awaiter(this, arguments, void 0, function* ({ abi, address, functionName, args = [], value = (0, viem_1.parseEther)('0'), signer, }) {
129
+ return tslib_1.__awaiter(this, arguments, void 0, function* ({ abi, address, functionName, args = [], value = BigInt(0), signer, }) {
131
130
  const data = (0, viem_1.encodeFunctionData)({
132
131
  abi: abi,
133
132
  functionName,
@@ -162,11 +161,9 @@ class EvmClient {
162
161
  * console.log(`ETH transfer sent: ${txHash}`);
163
162
  */
164
163
  sendTransaction(_a) {
165
- return tslib_1.__awaiter(this, arguments, void 0, function* ({ to, data, value = (0, viem_1.parseEther)('0'), signer, nonce: explicitNonce, gas: explicitGas, }) {
164
+ return tslib_1.__awaiter(this, arguments, void 0, function* ({ to, data, value = BigInt(0), signer, nonce: explicitNonce, gas: explicitGas, }) {
166
165
  // Estimate gas and fees first (can run in parallel)
167
166
  const [gas, feePerGas, chainId] = yield Promise.all([
168
- // Use explicit gas if provided (for batched txs where estimateGas may fail
169
- // due to uncommitted state), fixed gas for simple transfers, or estimate
170
167
  explicitGas
171
168
  ? Promise.resolve(explicitGas)
172
169
  : data === '0x'
@@ -180,9 +177,6 @@ class EvmClient {
180
177
  this.publicClient.estimateFeesPerGas(),
181
178
  this.publicClient.getChainId(),
182
179
  ]);
183
- // Use explicit nonce if provided (for sequential tx batches),
184
- // otherwise fetch after gas estimation to avoid stale nonce on Cosmos-EVM chains.
185
- // Use 'pending' blockTag to include mempool txs and prevent nonce collisions.
186
180
  const nonce = explicitNonce !== null && explicitNonce !== void 0 ? explicitNonce : yield this.publicClient.getTransactionCount({
187
181
  address: signer.account.address,
188
182
  blockTag: 'pending',
@@ -304,13 +298,11 @@ class EvmClient {
304
298
  */
305
299
  waitForConfirmations(_a) {
306
300
  return tslib_1.__awaiter(this, arguments, void 0, function* ({ txHash, confirmations = 3, pollIntervalMs = 1000, timeoutMs = 30000, }) {
307
- // first, wait for the tx to land in a block
308
301
  const receipt = yield this.publicClient.waitForTransactionReceipt({
309
302
  hash: txHash,
310
303
  });
311
304
  const targetBlock = receipt.blockNumber + BigInt(confirmations);
312
305
  const startTime = Date.now();
313
- // poll until we hit the target block or timeout
314
306
  // eslint-disable-next-line no-constant-condition
315
307
  while (true) {
316
308
  const currentBlock = yield this.publicClient.getBlockNumber();
@@ -46,8 +46,4 @@ export declare class SvmClient {
46
46
  instructions: TransactionInstruction[];
47
47
  signer: UniversalSigner;
48
48
  }): Promise<bigint>;
49
- /**
50
- * Sleeps for the given number of milliseconds.
51
- */
52
- private sleep;
53
49
  }
@@ -4,7 +4,7 @@ exports.SvmClient = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const web3_js_1 = require("@solana/web3.js");
6
6
  const anchor_1 = require("@coral-xyz/anchor");
7
- const anchor_2 = require("@coral-xyz/anchor");
7
+ const bs58_1 = require("../internal/bs58");
8
8
  // Universal Gateway ALT (shared with on-chain tests)
9
9
  const ALT_ADDRESS = new web3_js_1.PublicKey('EWXJ1ERkMwizmSovjtQ2qBTDpm1vxrZZ4Y2RjEujbqBo');
10
10
  /**
@@ -256,7 +256,7 @@ class SvmClient {
256
256
  throw new Error('signer.signTransaction is undefined');
257
257
  }
258
258
  const txHashBytes = yield signer.signAndSendTransaction(new Uint8Array(txBytes));
259
- return anchor_2.utils.bytes.bs58.encode(txHashBytes); // Clean, readable tx hash
259
+ return bs58_1.bs58.encode(Buffer.from(txHashBytes)); // Clean, readable tx hash
260
260
  });
261
261
  }
262
262
  /**
@@ -302,12 +302,6 @@ class SvmClient {
302
302
  }), 'estimateGas');
303
303
  });
304
304
  }
305
- /**
306
- * Sleeps for the given number of milliseconds.
307
- */
308
- sleep(ms) {
309
- return new Promise((resolve) => setTimeout(resolve, ms));
310
- }
311
305
  }
312
306
  exports.SvmClient = SvmClient;
313
307
  //# sourceMappingURL=svm-client.js.map
package/src/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/core/src/index.ts"],"names":[],"mappings":";;;AAAA,iDAA+C;AAE/C,gDAAsB;AACtB,8BAA8B;AAC9B,0BAA0B"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"cache.js","sourceRoot":"","sources":["../../../../../../packages/core/src/lib/cache/cache.ts"],"names":[],"mappings":";;;AAQA,MAAa,SAAS;IACpB,MAAM,CAAC,iBAAiB,CACtB,KAAY,EACZ,OAAe,EACf,WAAyB,EACzB,EAAM;QAEN,OAAO,uBAAuB,KAAK,IAAI,OAAO,IAAI,WAAW,IAAI,EAAE,EAAE,CAAC;IACxE,CAAC;IAED,MAAM,CAAC,gBAAgB,CAAC,OAAe;QACrC,OAAO,qBAAqB,OAAO,EAAE,CAAC;IACxC,CAAC;CACF;AAbD,8BAaC;AAED,MAAa,KAAK;IAIhB,YAAY,OAAO,GAAG,GAAG;QACvB,IAAI,CAAC,KAAK,GAAG,IAAI,GAAG,EAAE,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAEO,SAAS,CAAC,KAAiB;QACjC,IAAI,CAAC,KAAK,CAAC,GAAG;YAAE,OAAO,KAAK,CAAC;QAC7B,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,SAAS,GAAG,KAAK,CAAC,GAAG,CAAC;IAClD,CAAC;IAED,GAAG,CAAC,GAAW;QACb,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,OAAO,IAAI,CAAC;QAEtC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAElC,IAAI,KAAK,IAAI,SAAS,EAAE,CAAC;YACvB,IAAI,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC1B,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBACvB,OAAO,IAAI,CAAC;YACd,CAAC;YAED,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACvB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YAC3B,OAAO,KAAK,CAAC,KAAK,CAAC;QACrB,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,GAAG,CAAC,GAAW,EAAE,KAAU,EAAE,GAAY;QACvC,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACxB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACzB,CAAC;aAAM,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAC3C,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC;YACjD,IAAI,SAAS,IAAI,SAAS,EAAE,CAAC;gBAC3B,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;YAC/B,CAAC;QACH,CAAC;QAED,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE;YAClB,KAAK;YACL,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;YACrB,GAAG;SACJ,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,GAAW;QACf,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;IAED,QAAQ;QACN,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;IAED,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;IACzB,CAAC;CACF;AA5DD,sBA4DC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"cea.evm.js","sourceRoot":"","sources":["../../../../../../../packages/core/src/lib/constants/abi/cea.evm.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG;IACrB;QACE,QAAQ,EAAE;YACR;gBACE,cAAc,EAAE,SAAS;gBACzB,MAAM,EAAE,OAAO;gBACf,MAAM,EAAE,SAAS;aAClB;YACD;gBACE,cAAc,EAAE,SAAS;gBACzB,MAAM,EAAE,QAAQ;gBAChB,MAAM,EAAE,SAAS;aAClB;YACD;gBACE,cAAc,EAAE,OAAO;gBACvB,MAAM,EAAE,SAAS;gBACjB,MAAM,EAAE,OAAO;aAChB;YACD;gBACE,cAAc,EAAE,SAAS;gBACzB,MAAM,EAAE,iBAAiB;gBACzB,MAAM,EAAE,SAAS;aAClB;SACF;QACD,MAAM,EAAE,sBAAsB;QAC9B,SAAS,EAAE,EAAE;QACb,iBAAiB,EAAE,YAAY;QAC/B,MAAM,EAAE,UAAU;KACnB;CACO,CAAC"}