@pushchain/core 6.0.19 → 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 (112) hide show
  1. package/CHANGELOG.md +54 -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 +4 -1
  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 -331
  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.d.ts +2 -1
  98. package/src/lib/universal/signer/signer.js +315 -299
  99. package/src/lib/universal-tx-detector/auto-detect.js +55 -60
  100. package/src/lib/universal-tx-detector/cascade.js +160 -172
  101. package/src/lib/universal-tx-detector/child-inbounds.js +67 -75
  102. package/src/lib/universal-tx-detector/classify.js +2 -3
  103. package/src/lib/universal-tx-detector/detector-svm.js +139 -147
  104. package/src/lib/universal-tx-detector/detector.js +145 -157
  105. package/src/lib/universal-tx-detector/normalize.js +7 -7
  106. package/src/lib/utils/external-tx-hash.js +1 -2
  107. package/src/lib/utils.d.ts +44 -0
  108. package/src/lib/utils.js +762 -683
  109. package/src/lib/vm-client/evm-client.js +186 -202
  110. package/src/lib/vm-client/svm-client.d.ts +1 -1
  111. package/src/lib/vm-client/svm-client.js +220 -224
  112. package/src/lib/vm-client/vm-client.types.d.ts +14 -2
package/src/lib/index.js CHANGED
@@ -1,11 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PushChain = exports.buildErc20WithdrawalMulticall = exports.buildMigrationPayload = exports.isValidSolanaHexAddress = exports.isSvmChain = exports.encodeSvmExecutePayload = exports.getAllCEAAddresses = exports.getCEAFactoryAddress = exports.chainSupportsOutbound = exports.chainSupportsCEA = exports.isCEA = exports.getPushAccountForCEA = exports.getCEAAddress = exports.quoteMaxPCForGasCapFromNativeValue = exports.quoteMaxPCForGasCap = exports.MAX_PC_FOR_GAS_BUFFER_BPS_LIMIT = exports.DEFAULT_MAX_PC_FOR_GAS_BUFFER_BPS = exports.isChainTarget = exports.detectRoute = exports.TransactionRoute = exports.parseUEAVersion = void 0;
3
+ exports.PushChain = exports.buildErc20WithdrawalMulticall = exports.buildMigrationPayload = exports.isValidSolanaHexAddress = exports.isSvmChain = exports.encodeSvmExecutePayload = exports.getAllCEAAddresses = exports.getCEAFactoryAddress = exports.chainSupportsOutbound = exports.chainSupportsCEA = exports.isCEA = exports.getPushAccountForCEA = exports.getCEAAddress = exports.quoteMaxPCForGasCapFromNativeValue = exports.quoteMaxPCForGasCap = exports.MAX_PC_FOR_GAS_BUFFER_BPS_LIMIT = exports.DEFAULT_MAX_PC_FOR_GAS_BUFFER_BPS = exports.isChainTarget = exports.detectRoute = exports.TransactionRoute = exports.parseUEAVersion = exports.PC20UnsafeEmptyPayloadError = exports.PC20ExportRevertedError = exports.PC20WrapperPredictionUnavailableError = exports.PC20UnknownChainNamespaceError = exports.InsufficientPC20BalanceError = exports.UnsupportedPC20DestinationError = exports.PC20AmbiguousAddressError = exports.PC20ExpectedButPRC20Error = exports.InvalidPC20MetadataError = exports.PC20FactoryMismatchError = exports.PC20RegistryMismatchError = exports.PC20WrapperNotRegisteredError = exports.PC20TokenChainMismatchError = exports.InvalidPC20AddressError = exports.PC20Error = exports.isPC20Reference = void 0;
4
4
  const push_chain_1 = require("./push-chain/push-chain");
5
5
  Object.defineProperty(exports, "PushChain", { enumerable: true, get: function () { return push_chain_1.PushChain; } });
6
- // UEA version utility
7
6
  var orchestrator_types_1 = require("./orchestrator/orchestrator.types");
8
- Object.defineProperty(exports, "parseUEAVersion", { enumerable: true, get: function () { return orchestrator_types_1.parseUEAVersion; } });
7
+ Object.defineProperty(exports, "isPC20Reference", { enumerable: true, get: function () { return orchestrator_types_1.isPC20Reference; } });
8
+ var errors_1 = require("./orchestrator/internals/pc20/errors");
9
+ Object.defineProperty(exports, "PC20Error", { enumerable: true, get: function () { return errors_1.PC20Error; } });
10
+ Object.defineProperty(exports, "InvalidPC20AddressError", { enumerable: true, get: function () { return errors_1.InvalidPC20AddressError; } });
11
+ Object.defineProperty(exports, "PC20TokenChainMismatchError", { enumerable: true, get: function () { return errors_1.PC20TokenChainMismatchError; } });
12
+ Object.defineProperty(exports, "PC20WrapperNotRegisteredError", { enumerable: true, get: function () { return errors_1.PC20WrapperNotRegisteredError; } });
13
+ Object.defineProperty(exports, "PC20RegistryMismatchError", { enumerable: true, get: function () { return errors_1.PC20RegistryMismatchError; } });
14
+ Object.defineProperty(exports, "PC20FactoryMismatchError", { enumerable: true, get: function () { return errors_1.PC20FactoryMismatchError; } });
15
+ Object.defineProperty(exports, "InvalidPC20MetadataError", { enumerable: true, get: function () { return errors_1.InvalidPC20MetadataError; } });
16
+ Object.defineProperty(exports, "PC20ExpectedButPRC20Error", { enumerable: true, get: function () { return errors_1.PC20ExpectedButPRC20Error; } });
17
+ Object.defineProperty(exports, "PC20AmbiguousAddressError", { enumerable: true, get: function () { return errors_1.PC20AmbiguousAddressError; } });
18
+ Object.defineProperty(exports, "UnsupportedPC20DestinationError", { enumerable: true, get: function () { return errors_1.UnsupportedPC20DestinationError; } });
19
+ Object.defineProperty(exports, "InsufficientPC20BalanceError", { enumerable: true, get: function () { return errors_1.InsufficientPC20BalanceError; } });
20
+ Object.defineProperty(exports, "PC20UnknownChainNamespaceError", { enumerable: true, get: function () { return errors_1.PC20UnknownChainNamespaceError; } });
21
+ Object.defineProperty(exports, "PC20WrapperPredictionUnavailableError", { enumerable: true, get: function () { return errors_1.PC20WrapperPredictionUnavailableError; } });
22
+ Object.defineProperty(exports, "PC20ExportRevertedError", { enumerable: true, get: function () { return errors_1.PC20ExportRevertedError; } });
23
+ Object.defineProperty(exports, "PC20UnsafeEmptyPayloadError", { enumerable: true, get: function () { return errors_1.PC20UnsafeEmptyPayloadError; } });
24
+ // UEA version utility
25
+ var orchestrator_types_2 = require("./orchestrator/orchestrator.types");
26
+ Object.defineProperty(exports, "parseUEAVersion", { enumerable: true, get: function () { return orchestrator_types_2.parseUEAVersion; } });
9
27
  // Route detection utilities
10
28
  var route_detector_1 = require("./orchestrator/route-detector");
11
29
  Object.defineProperty(exports, "TransactionRoute", { enumerable: true, get: function () { return route_detector_1.TransactionRoute; } });
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
- var _a;
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.Buffer = void 0;
5
4
  const buffer_1 = require("buffer");
6
- exports.Buffer = (_a = globalThis.Buffer) !== null && _a !== void 0 ? _a : buffer_1.Buffer;
5
+ exports.Buffer = globalThis.Buffer ?? buffer_1.Buffer;
7
6
  //# sourceMappingURL=buffer.js.map
@@ -12,7 +12,6 @@ exports.chainSupportsCEA = chainSupportsCEA;
12
12
  exports.chainSupportsOutbound = chainSupportsOutbound;
13
13
  exports.getCEAFactoryAddress = getCEAFactoryAddress;
14
14
  exports.getAllCEAAddresses = getAllCEAAddresses;
15
- const tslib_1 = require("tslib");
16
15
  const viem_1 = require("viem");
17
16
  const chains_1 = require("viem/chains");
18
17
  const enums_1 = require("../constants/enums");
@@ -49,33 +48,31 @@ function getViemChain(chain) {
49
48
  // Cache CEA address per UEA+chain — address is deterministic (CREATE2), but
50
49
  // isDeployed can change during execution so we always re-fetch it.
51
50
  const ceaAddressCache = new Map();
52
- function getCEAAddress(ueaAddress, chain, rpcUrl) {
53
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
54
- const cacheKey = `${ueaAddress.toLowerCase()}:${chain}`;
55
- const cachedAddress = ceaAddressCache.get(cacheKey);
56
- const factoryAddress = chain_1.CEA_FACTORY_ADDRESSES[chain];
57
- if (!factoryAddress) {
58
- throw new Error(`CEAFactory not available on chain ${chain}`);
59
- }
60
- const viemChain = getViemChain(chain);
61
- const client = (0, viem_1.createPublicClient)({
62
- chain: viemChain,
63
- transport: (0, viem_1.http)(rpcUrl),
64
- });
65
- if (cachedAddress) {
66
- // Address is cached — only re-check deployment status
67
- const code = yield client.getCode({ address: cachedAddress });
68
- return { cea: cachedAddress, isDeployed: code !== undefined && code !== '0x' };
69
- }
70
- const [cea, isDeployed] = yield client.readContract({
71
- abi: ceaFactory_evm_1.CEA_FACTORY_EVM,
72
- address: factoryAddress,
73
- functionName: 'getCEAForPushAccount',
74
- args: [ueaAddress],
75
- });
76
- ceaAddressCache.set(cacheKey, cea);
77
- return { cea, isDeployed };
51
+ async function getCEAAddress(ueaAddress, chain, rpcUrl) {
52
+ const cacheKey = `${ueaAddress.toLowerCase()}:${chain}`;
53
+ const cachedAddress = ceaAddressCache.get(cacheKey);
54
+ const factoryAddress = chain_1.CEA_FACTORY_ADDRESSES[chain];
55
+ if (!factoryAddress) {
56
+ throw new Error(`CEAFactory not available on chain ${chain}`);
57
+ }
58
+ const viemChain = getViemChain(chain);
59
+ const client = (0, viem_1.createPublicClient)({
60
+ chain: viemChain,
61
+ transport: (0, viem_1.http)(rpcUrl),
78
62
  });
63
+ if (cachedAddress) {
64
+ // Address is cached — only re-check deployment status
65
+ const code = await client.getCode({ address: cachedAddress });
66
+ return { cea: cachedAddress, isDeployed: code !== undefined && code !== '0x' };
67
+ }
68
+ const [cea, isDeployed] = await client.readContract({
69
+ abi: ceaFactory_evm_1.CEA_FACTORY_EVM,
70
+ address: factoryAddress,
71
+ functionName: 'getCEAForPushAccount',
72
+ args: [ueaAddress],
73
+ });
74
+ ceaAddressCache.set(cacheKey, cea);
75
+ return { cea, isDeployed };
79
76
  }
80
77
  /**
81
78
  * Get Push Account (UEA) address for a CEA on a specific chain
@@ -86,25 +83,23 @@ function getCEAAddress(ueaAddress, chain, rpcUrl) {
86
83
  * @returns Push account address on Push Chain
87
84
  * @throws Error if chain doesn't have CEAFactory
88
85
  */
89
- function getPushAccountForCEA(ceaAddress, chain, rpcUrl) {
90
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
91
- const factoryAddress = chain_1.CEA_FACTORY_ADDRESSES[chain];
92
- if (!factoryAddress) {
93
- throw new Error(`CEAFactory not available on chain ${chain}`);
94
- }
95
- const viemChain = getViemChain(chain);
96
- const client = (0, viem_1.createPublicClient)({
97
- chain: viemChain,
98
- transport: (0, viem_1.http)(rpcUrl),
99
- });
100
- const uea = yield client.readContract({
101
- abi: ceaFactory_evm_1.CEA_FACTORY_EVM,
102
- address: factoryAddress,
103
- functionName: 'getPushAccountForCEA',
104
- args: [ceaAddress],
105
- });
106
- return uea;
86
+ async function getPushAccountForCEA(ceaAddress, chain, rpcUrl) {
87
+ const factoryAddress = chain_1.CEA_FACTORY_ADDRESSES[chain];
88
+ if (!factoryAddress) {
89
+ throw new Error(`CEAFactory not available on chain ${chain}`);
90
+ }
91
+ const viemChain = getViemChain(chain);
92
+ const client = (0, viem_1.createPublicClient)({
93
+ chain: viemChain,
94
+ transport: (0, viem_1.http)(rpcUrl),
107
95
  });
96
+ const uea = await client.readContract({
97
+ abi: ceaFactory_evm_1.CEA_FACTORY_EVM,
98
+ address: factoryAddress,
99
+ functionName: 'getPushAccountForCEA',
100
+ args: [ceaAddress],
101
+ });
102
+ return uea;
108
103
  }
109
104
  /**
110
105
  * Check if an address is a CEA on a specific chain
@@ -115,23 +110,21 @@ function getPushAccountForCEA(ceaAddress, chain, rpcUrl) {
115
110
  * @returns True if address is a CEA deployed by the factory
116
111
  * @throws Error if chain doesn't have CEAFactory
117
112
  */
118
- function isCEA(address, chain, rpcUrl) {
119
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
120
- const factoryAddress = chain_1.CEA_FACTORY_ADDRESSES[chain];
121
- if (!factoryAddress) {
122
- throw new Error(`CEAFactory not available on chain ${chain}`);
123
- }
124
- const viemChain = getViemChain(chain);
125
- const client = (0, viem_1.createPublicClient)({
126
- chain: viemChain,
127
- transport: (0, viem_1.http)(rpcUrl),
128
- });
129
- return client.readContract({
130
- abi: ceaFactory_evm_1.CEA_FACTORY_EVM,
131
- address: factoryAddress,
132
- functionName: 'isCEA',
133
- args: [address],
134
- });
113
+ async function isCEA(address, chain, rpcUrl) {
114
+ const factoryAddress = chain_1.CEA_FACTORY_ADDRESSES[chain];
115
+ if (!factoryAddress) {
116
+ throw new Error(`CEAFactory not available on chain ${chain}`);
117
+ }
118
+ const viemChain = getViemChain(chain);
119
+ const client = (0, viem_1.createPublicClient)({
120
+ chain: viemChain,
121
+ transport: (0, viem_1.http)(rpcUrl),
122
+ });
123
+ return client.readContract({
124
+ abi: ceaFactory_evm_1.CEA_FACTORY_EVM,
125
+ address: factoryAddress,
126
+ functionName: 'isCEA',
127
+ args: [address],
135
128
  });
136
129
  }
137
130
  /**
@@ -152,8 +145,7 @@ function chainSupportsCEA(chain) {
152
145
  * @returns True if outbound transactions are supported
153
146
  */
154
147
  function chainSupportsOutbound(chain) {
155
- var _a;
156
- if (((_a = chain_1.CHAIN_INFO[chain]) === null || _a === void 0 ? void 0 : _a.vm) === enums_1.VM.SVM) {
148
+ if (chain_1.CHAIN_INFO[chain]?.vm === enums_1.VM.SVM) {
157
149
  return true; // SVM uses gateway program, not CEA
158
150
  }
159
151
  return chain_1.CEA_FACTORY_ADDRESSES[chain] !== undefined;
@@ -174,24 +166,22 @@ function getCEAFactoryAddress(chain) {
174
166
  * @param rpcUrls - Optional custom RPC URLs per chain
175
167
  * @returns Array of CEA addresses per chain
176
168
  */
177
- function getAllCEAAddresses(ueaAddress, rpcUrls) {
178
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
179
- const chains = Object.keys(chain_1.CEA_FACTORY_ADDRESSES);
180
- const results = yield Promise.all(chains.map((chain) => tslib_1.__awaiter(this, void 0, void 0, function* () {
181
- try {
182
- const { cea, isDeployed } = yield getCEAAddress(ueaAddress, chain, rpcUrls === null || rpcUrls === void 0 ? void 0 : rpcUrls[chain]);
183
- return { chain, cea, isDeployed };
184
- }
185
- catch (error) {
186
- return {
187
- chain,
188
- cea: '0x0000000000000000000000000000000000000000',
189
- isDeployed: false,
190
- error: error instanceof Error ? error.message : String(error),
191
- };
192
- }
193
- })));
194
- return results;
195
- });
169
+ async function getAllCEAAddresses(ueaAddress, rpcUrls) {
170
+ const chains = Object.keys(chain_1.CEA_FACTORY_ADDRESSES);
171
+ const results = await Promise.all(chains.map(async (chain) => {
172
+ try {
173
+ const { cea, isDeployed } = await getCEAAddress(ueaAddress, chain, rpcUrls?.[chain]);
174
+ return { chain, cea, isDeployed };
175
+ }
176
+ catch (error) {
177
+ return {
178
+ chain,
179
+ cea: '0x0000000000000000000000000000000000000000',
180
+ isDeployed: false,
181
+ error: error instanceof Error ? error.message : String(error),
182
+ };
183
+ }
184
+ }));
185
+ return results;
196
186
  }
197
187
  //# sourceMappingURL=cea-utils.js.map
@@ -24,168 +24,159 @@ const helpers_1 = require("./helpers");
24
24
  // ============================================================================
25
25
  // Fetch Latest UEA Version from Factory
26
26
  // ============================================================================
27
- function fetchLatestUEAVersion(ctx, vm) {
28
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
29
- const factoryAddress = chain_1.UEA_FACTORY[ctx.pushNetwork];
30
- if (!factoryAddress || factoryAddress === '0xTBD') {
31
- return '';
32
- }
33
- try {
34
- const vmHash = vm === enums_1.VM.EVM
35
- ? (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([{ type: 'string' }], ['EVM']))
36
- : (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([{ type: 'string' }], ['SVM']));
37
- return yield ctx.pushClient.readContract({
38
- address: factoryAddress,
39
- abi: uea_factory_1.UEA_FACTORY_ABI,
40
- functionName: 'UEA_VERSION',
41
- args: [vmHash],
42
- });
43
- }
44
- catch (_a) {
45
- return '';
46
- }
47
- });
27
+ async function fetchLatestUEAVersion(ctx, vm) {
28
+ const factoryAddress = chain_1.UEA_FACTORY[ctx.pushNetwork];
29
+ if (!factoryAddress || factoryAddress === '0xTBD') {
30
+ return '';
31
+ }
32
+ try {
33
+ const vmHash = vm === enums_1.VM.EVM
34
+ ? (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([{ type: 'string' }], ['EVM']))
35
+ : (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([{ type: 'string' }], ['SVM']));
36
+ return await ctx.pushClient.readContract({
37
+ address: factoryAddress,
38
+ abi: uea_factory_1.UEA_FACTORY_ABI,
39
+ functionName: 'UEA_VERSION',
40
+ args: [vmHash],
41
+ });
42
+ }
43
+ catch {
44
+ return '';
45
+ }
48
46
  }
49
47
  // ============================================================================
50
48
  // Account Status
51
49
  // ============================================================================
52
- function getAccountStatus(ctx, options) {
53
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
54
- if (ctx.accountStatusCache && !(options === null || options === void 0 ? void 0 : options.forceRefresh)) {
55
- return ctx.accountStatusCache;
56
- }
57
- const chain = ctx.universalSigner.account.chain;
58
- const { vm } = chain_1.CHAIN_INFO[chain];
59
- const { deployed } = yield (0, uea_manager_1.getUeaStatusAndNonce)(ctx);
60
- if (!deployed) {
61
- const status = {
62
- mode: 'signer',
63
- uea: {
64
- loaded: true,
65
- deployed: false,
66
- version: '',
67
- minRequiredVersion: '',
68
- requiresUpgrade: false,
69
- },
70
- };
71
- ctx.accountStatusCache = status;
72
- return status;
73
- }
74
- const [currentVersion, minRequiredVersion] = yield Promise.all([
75
- (0, uea_manager_1.fetchUEAVersion)(ctx),
76
- fetchLatestUEAVersion(ctx, vm),
77
- ]);
78
- const requiresUpgrade = (0, orchestrator_types_1.parseUEAVersion)(currentVersion) < (0, orchestrator_types_1.parseUEAVersion)(minRequiredVersion);
50
+ async function getAccountStatus(ctx, options) {
51
+ if (ctx.accountStatusCache && !options?.forceRefresh) {
52
+ return ctx.accountStatusCache;
53
+ }
54
+ const chain = ctx.universalSigner.account.chain;
55
+ const { vm } = chain_1.CHAIN_INFO[chain];
56
+ const { deployed } = await (0, uea_manager_1.getUeaStatusAndNonce)(ctx);
57
+ if (!deployed) {
79
58
  const status = {
80
59
  mode: 'signer',
81
60
  uea: {
82
61
  loaded: true,
83
- deployed: true,
84
- version: currentVersion,
85
- minRequiredVersion,
86
- requiresUpgrade,
62
+ deployed: false,
63
+ version: '',
64
+ minRequiredVersion: '',
65
+ requiresUpgrade: false,
87
66
  },
88
67
  };
89
68
  ctx.accountStatusCache = status;
90
69
  return status;
91
- });
70
+ }
71
+ const [currentVersion, minRequiredVersion] = await Promise.all([
72
+ (0, uea_manager_1.fetchUEAVersion)(ctx),
73
+ fetchLatestUEAVersion(ctx, vm),
74
+ ]);
75
+ const requiresUpgrade = (0, orchestrator_types_1.parseUEAVersion)(currentVersion) < (0, orchestrator_types_1.parseUEAVersion)(minRequiredVersion);
76
+ const status = {
77
+ mode: 'signer',
78
+ uea: {
79
+ loaded: true,
80
+ deployed: true,
81
+ version: currentVersion,
82
+ minRequiredVersion,
83
+ requiresUpgrade,
84
+ },
85
+ };
86
+ ctx.accountStatusCache = status;
87
+ return status;
92
88
  }
93
89
  // ============================================================================
94
90
  // UEA Upgrade
95
91
  // ============================================================================
96
- function upgradeAccount(ctx, options) {
97
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
98
- const hook = (options === null || options === void 0 ? void 0 : options.progressHook) || ctx.progressHook;
99
- const fireHook = (hookId, ...args) => {
100
- const hookEntry = progress_hook_1.default[hookId];
101
- if (hookEntry && hook) {
102
- hook(hookEntry(...args));
103
- }
104
- };
105
- fireHook(progress_hook_types_1.PROGRESS_HOOK.UEA_MIG_01);
106
- const status = yield getAccountStatus(ctx, { forceRefresh: true });
107
- if (!status.uea.requiresUpgrade) {
108
- fireHook(progress_hook_types_1.PROGRESS_HOOK.UEA_MIG_9903);
109
- return;
92
+ async function upgradeAccount(ctx, options) {
93
+ const hook = options?.progressHook || ctx.progressHook;
94
+ const fireHook = (hookId, ...args) => {
95
+ const hookEntry = progress_hook_1.default[hookId];
96
+ if (hookEntry && hook) {
97
+ hook(hookEntry(...args));
110
98
  }
111
- fireHook(progress_hook_types_1.PROGRESS_HOOK.UEA_MIG_02);
112
- try {
113
- const { chain, address } = ctx.universalSigner.account;
114
- const { vm, chainId } = chain_1.CHAIN_INFO[chain];
115
- const ueaAddress = (0, uea_manager_1.computeUEAOffchain)(ctx);
116
- const migrationContractAddress = chain_1.UEA_MIGRATION[ctx.pushNetwork];
117
- if (!migrationContractAddress || migrationContractAddress === '0xTBD') {
118
- throw new Error('UEA migration contract address not configured');
119
- }
120
- const { nonce } = yield (0, uea_manager_1.getUeaStatusAndNonce)(ctx);
121
- const deadline = BigInt(9999999999);
122
- const ueaVersion = status.uea.version || '0.1.0';
123
- const signatureBytes = yield (0, signing_1.signMigrationPayload)(ctx, {
124
- migrationContractAddress,
125
- nonce,
126
- deadline,
127
- ueaVersion,
128
- ueaAddress,
129
- });
130
- const signature = (0, viem_1.bytesToHex)(signatureBytes);
131
- fireHook(progress_hook_types_1.PROGRESS_HOOK.UEA_MIG_03);
132
- const universalAccountId = {
133
- chainNamespace: chain_1.VM_NAMESPACE[vm],
134
- chainId,
135
- owner: vm === enums_1.VM.EVM
136
- ? address
137
- : vm === enums_1.VM.SVM
138
- ? (0, viem_1.bytesToHex)(new Uint8Array(bs58_1.bs58.decode(address)))
139
- : address,
140
- };
141
- const { cosmosAddress: signer } = ctx.pushClient.getSignerAddress();
142
- const msg = ctx.pushClient.createMsgMigrateUEA({
143
- signer,
144
- universalAccountId,
145
- migrationPayload: {
146
- migration: migrationContractAddress,
147
- nonce: nonce.toString(),
148
- deadline: deadline.toString(),
149
- },
150
- signature,
151
- });
152
- const txBody = yield ctx.pushClient.createCosmosTxBody([msg]);
153
- const txRaw = yield ctx.pushClient.signCosmosTx(txBody);
154
- const tx = yield ctx.pushClient.broadcastCosmosTx(txRaw);
155
- if (tx.code !== 0) {
156
- throw new Error(tx.rawLog || 'UEA migration transaction failed');
157
- }
158
- ctx.ueaVersionCache = undefined;
159
- const updated = yield getAccountStatus(ctx, { forceRefresh: true });
160
- fireHook(progress_hook_types_1.PROGRESS_HOOK.UEA_MIG_9901, updated.uea.version);
99
+ };
100
+ fireHook(progress_hook_types_1.PROGRESS_HOOK.UEA_MIG_01);
101
+ const status = await getAccountStatus(ctx, { forceRefresh: true });
102
+ if (!status.uea.requiresUpgrade) {
103
+ fireHook(progress_hook_types_1.PROGRESS_HOOK.UEA_MIG_9903);
104
+ return;
105
+ }
106
+ fireHook(progress_hook_types_1.PROGRESS_HOOK.UEA_MIG_02);
107
+ try {
108
+ const { chain, address } = ctx.universalSigner.account;
109
+ const { vm, chainId } = chain_1.CHAIN_INFO[chain];
110
+ const ueaAddress = (0, uea_manager_1.computeUEAOffchain)(ctx);
111
+ const migrationContractAddress = chain_1.UEA_MIGRATION[ctx.pushNetwork];
112
+ if (!migrationContractAddress || migrationContractAddress === '0xTBD') {
113
+ throw new Error('UEA migration contract address not configured');
161
114
  }
162
- catch (err) {
163
- fireHook(progress_hook_types_1.PROGRESS_HOOK.UEA_MIG_9902);
164
- throw err;
115
+ const { nonce } = await (0, uea_manager_1.getUeaStatusAndNonce)(ctx);
116
+ const deadline = BigInt(9999999999);
117
+ const ueaVersion = status.uea.version || '0.1.0';
118
+ const signatureBytes = await (0, signing_1.signMigrationPayload)(ctx, {
119
+ migrationContractAddress,
120
+ nonce,
121
+ deadline,
122
+ ueaVersion,
123
+ ueaAddress,
124
+ });
125
+ const signature = (0, viem_1.bytesToHex)(signatureBytes);
126
+ fireHook(progress_hook_types_1.PROGRESS_HOOK.UEA_MIG_03);
127
+ const universalAccountId = {
128
+ chainNamespace: chain_1.VM_NAMESPACE[vm],
129
+ chainId,
130
+ owner: vm === enums_1.VM.EVM
131
+ ? address
132
+ : vm === enums_1.VM.SVM
133
+ ? (0, viem_1.bytesToHex)(new Uint8Array(bs58_1.bs58.decode(address)))
134
+ : address,
135
+ };
136
+ const { cosmosAddress: signer } = ctx.pushClient.getSignerAddress();
137
+ const msg = ctx.pushClient.createMsgMigrateUEA({
138
+ signer,
139
+ universalAccountId,
140
+ migrationPayload: {
141
+ migration: migrationContractAddress,
142
+ nonce: nonce.toString(),
143
+ deadline: deadline.toString(),
144
+ },
145
+ signature,
146
+ });
147
+ const txBody = await ctx.pushClient.createCosmosTxBody([msg]);
148
+ const txRaw = await ctx.pushClient.signCosmosTx(txBody);
149
+ const tx = await ctx.pushClient.broadcastCosmosTx(txRaw);
150
+ if (tx.code !== 0) {
151
+ throw new Error(tx.rawLog || 'UEA migration transaction failed');
165
152
  }
166
- });
153
+ ctx.ueaVersionCache = undefined;
154
+ const updated = await getAccountStatus(ctx, { forceRefresh: true });
155
+ fireHook(progress_hook_types_1.PROGRESS_HOOK.UEA_MIG_9901, updated.uea.version);
156
+ }
157
+ catch (err) {
158
+ fireHook(progress_hook_types_1.PROGRESS_HOOK.UEA_MIG_9902);
159
+ throw err;
160
+ }
167
161
  }
168
162
  // ============================================================================
169
163
  // CEA Migration
170
164
  // ============================================================================
171
- function migrateCEA(ctx, chain, executeFn) {
172
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
173
- var _a;
174
- if ((0, helpers_1.isPushChain)(chain)) {
175
- throw new Error('Cannot migrate CEA on Push Chain');
176
- }
177
- if (!(0, cea_utils_1.chainSupportsCEA)(chain)) {
178
- throw new Error(`Chain ${chain} does not support CEA`);
179
- }
180
- const ueaAddress = (0, uea_manager_1.computeUEAOffchain)(ctx);
181
- const { cea, isDeployed } = yield (0, cea_utils_1.getCEAAddress)(ueaAddress, chain, (_a = ctx.rpcUrls[chain]) === null || _a === void 0 ? void 0 : _a[0]);
182
- if (!isDeployed) {
183
- throw new Error(`CEA not deployed on chain ${chain}. Deploy CEA first.`);
184
- }
185
- return executeFn({
186
- to: { address: cea, chain },
187
- migration: true,
188
- });
165
+ async function migrateCEA(ctx, chain, executeFn) {
166
+ if ((0, helpers_1.isPushChain)(chain)) {
167
+ throw new Error('Cannot migrate CEA on Push Chain');
168
+ }
169
+ if (!(0, cea_utils_1.chainSupportsCEA)(chain)) {
170
+ throw new Error(`Chain ${chain} does not support CEA`);
171
+ }
172
+ const ueaAddress = (0, uea_manager_1.computeUEAOffchain)(ctx);
173
+ const { cea, isDeployed } = await (0, cea_utils_1.getCEAAddress)(ueaAddress, chain, ctx.rpcUrls[chain]?.[0]);
174
+ if (!isDeployed) {
175
+ throw new Error(`CEA not deployed on chain ${chain}. Deploy CEA first.`);
176
+ }
177
+ return executeFn({
178
+ to: { address: cea, chain },
179
+ migration: true,
189
180
  });
190
181
  }
191
182
  //# sourceMappingURL=account-manager.js.map
@@ -1,9 +1,3 @@
1
- /**
2
- * Cascade composition functions extracted from Orchestrator.
3
- *
4
- * Covers: prepareTransaction, buildHopDescriptor, classifyIntoSegments,
5
- * getSegmentType, composeCascade, createCascadedBuilder, createChainedBuilder.
6
- */
7
1
  import { TransactionRoute } from '../route-detector';
8
2
  import type { HopDescriptor, CascadeSegment, CascadeSegmentType, PreparedUniversalTx, CascadedTxResponse, CascadeHopInfo, UniversalTxResponse, UniversalExecuteParams, MultiCall, CascadeExecutionOptions, WaitForOutboundOptions, OutboundTxDetails } from '../orchestrator.types';
9
3
  import type { OrchestratorContext } from './context';