@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.
- package/CHANGELOG.md +54 -0
- package/package.json +1 -1
- package/src/lib/cache/cache.js +2 -0
- package/src/lib/constants/abi/index.d.ts +1 -0
- package/src/lib/constants/abi/index.js +8 -1
- package/src/lib/constants/abi/pc20.evm.d.ts +217 -0
- package/src/lib/constants/abi/pc20.evm.js +150 -0
- package/src/lib/constants/abi/prc20.evm.d.ts +172 -0
- package/src/lib/constants/abi/prc20.evm.js +97 -0
- package/src/lib/constants/abi/universalGatewayV0.json +1 -1
- package/src/lib/constants/chain.js +38 -8
- package/src/lib/constants/selectors.js +2 -2
- package/src/lib/constants/tokens.js +4 -3
- package/src/lib/formatters.js +16 -6
- package/src/lib/generated/uexecutor/v1/query.js +2 -4
- package/src/lib/generated/uexecutor/v1/types.d.ts +14 -0
- package/src/lib/generated/uexecutor/v1/types.js +90 -47
- package/src/lib/generated/uexecutor/v2/query.js +2 -4
- package/src/lib/generated/uexecutor/v2/types.d.ts +20 -0
- package/src/lib/generated/uexecutor/v2/types.js +49 -33
- package/src/lib/generated/v1/tx.js +30 -37
- package/src/lib/index.d.ts +4 -1
- package/src/lib/index.js +21 -3
- package/src/lib/internal/buffer.js +1 -2
- package/src/lib/orchestrator/cea-utils.js +73 -83
- package/src/lib/orchestrator/internals/account-manager.js +130 -139
- package/src/lib/orchestrator/internals/cascade.d.ts +0 -6
- package/src/lib/orchestrator/internals/cascade.js +1184 -1059
- package/src/lib/orchestrator/internals/confirmation.js +138 -148
- package/src/lib/orchestrator/internals/error-decoder.js +1 -1
- package/src/lib/orchestrator/internals/errors.js +12 -3
- package/src/lib/orchestrator/internals/execute-funds-only.d.ts +2 -2
- package/src/lib/orchestrator/internals/execute-funds-only.js +297 -259
- package/src/lib/orchestrator/internals/execute-funds-payload.d.ts +2 -2
- package/src/lib/orchestrator/internals/execute-funds-payload.js +220 -220
- package/src/lib/orchestrator/internals/execute-standard.d.ts +0 -8
- package/src/lib/orchestrator/internals/execute-standard.js +339 -342
- package/src/lib/orchestrator/internals/gas-calculator.js +497 -520
- package/src/lib/orchestrator/internals/gas-usd-sizer.js +101 -110
- package/src/lib/orchestrator/internals/gateway-client.js +102 -103
- package/src/lib/orchestrator/internals/helpers.js +30 -27
- package/src/lib/orchestrator/internals/inbound-tracker.js +234 -238
- package/src/lib/orchestrator/internals/outbound-sync.js +463 -452
- package/src/lib/orchestrator/internals/outbound-tracker.js +27 -34
- package/src/lib/orchestrator/internals/payload-builder.d.ts +2 -2
- package/src/lib/orchestrator/internals/payload-builder.js +119 -100
- package/src/lib/orchestrator/internals/pc-usd-oracle.js +121 -129
- package/src/lib/orchestrator/internals/pc20/address-codec.d.ts +31 -0
- package/src/lib/orchestrator/internals/pc20/address-codec.js +124 -0
- package/src/lib/orchestrator/internals/pc20/chain-namespace.d.ts +68 -0
- package/src/lib/orchestrator/internals/pc20/chain-namespace.js +136 -0
- package/src/lib/orchestrator/internals/pc20/errors.d.ts +160 -0
- package/src/lib/orchestrator/internals/pc20/errors.js +236 -0
- package/src/lib/orchestrator/internals/pc20/export.d.ts +172 -0
- package/src/lib/orchestrator/internals/pc20/export.js +412 -0
- package/src/lib/orchestrator/internals/pc20/gate.d.ts +67 -0
- package/src/lib/orchestrator/internals/pc20/gate.js +184 -0
- package/src/lib/orchestrator/internals/pc20/resolver.d.ts +187 -0
- package/src/lib/orchestrator/internals/pc20/resolver.js +658 -0
- package/src/lib/orchestrator/internals/pc20/svm.d.ts +189 -0
- package/src/lib/orchestrator/internals/pc20/svm.js +286 -0
- package/src/lib/orchestrator/internals/pc20/tracking.d.ts +46 -0
- package/src/lib/orchestrator/internals/pc20/tracking.js +109 -0
- package/src/lib/orchestrator/internals/preflight.js +1 -1
- package/src/lib/orchestrator/internals/progress-route-hooks.js +2 -2
- package/src/lib/orchestrator/internals/push-chain-tx.js +319 -331
- package/src/lib/orchestrator/internals/quote.js +90 -94
- package/src/lib/orchestrator/internals/rescue.js +76 -79
- package/src/lib/orchestrator/internals/response-builder.d.ts +28 -1
- package/src/lib/orchestrator/internals/response-builder.js +817 -701
- package/src/lib/orchestrator/internals/route-handlers.d.ts +7 -15
- package/src/lib/orchestrator/internals/route-handlers.js +1512 -1178
- package/src/lib/orchestrator/internals/signing.js +78 -83
- package/src/lib/orchestrator/internals/svm-bridge.d.ts +2 -2
- package/src/lib/orchestrator/internals/svm-bridge.js +161 -93
- package/src/lib/orchestrator/internals/svm-helpers.d.ts +15 -1
- package/src/lib/orchestrator/internals/svm-helpers.js +68 -24
- package/src/lib/orchestrator/internals/svm-rent.d.ts +19 -1
- package/src/lib/orchestrator/internals/svm-rent.js +163 -141
- package/src/lib/orchestrator/internals/tx-transformer.js +26 -23
- package/src/lib/orchestrator/internals/uea-manager.js +89 -86
- package/src/lib/orchestrator/max-pc-for-gas.js +5 -6
- package/src/lib/orchestrator/orchestrator.js +217 -200
- package/src/lib/orchestrator/orchestrator.types.d.ts +121 -1
- package/src/lib/orchestrator/orchestrator.types.js +19 -0
- package/src/lib/orchestrator/payload-builders.d.ts +2 -2
- package/src/lib/orchestrator/payload-builders.js +26 -24
- package/src/lib/orchestrator/route-detector.js +26 -9
- package/src/lib/orchestrator/svm-idl/ix-encoder.js +1 -2
- package/src/lib/orchestrator/svm-idl/normalize-address.js +2 -2
- package/src/lib/orchestrator/svm-idl/resolve.js +1 -2
- package/src/lib/price-fetch/price-fetch.js +67 -68
- package/src/lib/progress-hook/progress-hook.js +124 -72
- package/src/lib/push-chain/push-chain.js +171 -153
- package/src/lib/push-client/push-client.js +223 -237
- package/src/lib/universal/account/account.js +349 -365
- package/src/lib/universal/signer/signer.d.ts +2 -1
- package/src/lib/universal/signer/signer.js +315 -299
- package/src/lib/universal-tx-detector/auto-detect.js +55 -60
- package/src/lib/universal-tx-detector/cascade.js +160 -172
- package/src/lib/universal-tx-detector/child-inbounds.js +67 -75
- package/src/lib/universal-tx-detector/classify.js +2 -3
- package/src/lib/universal-tx-detector/detector-svm.js +139 -147
- package/src/lib/universal-tx-detector/detector.js +145 -157
- package/src/lib/universal-tx-detector/normalize.js +7 -7
- package/src/lib/utils/external-tx-hash.js +1 -2
- package/src/lib/utils.d.ts +44 -0
- package/src/lib/utils.js +762 -683
- package/src/lib/vm-client/evm-client.js +186 -202
- package/src/lib/vm-client/svm-client.d.ts +1 -1
- package/src/lib/vm-client/svm-client.js +220 -224
- package/src/lib/vm-client/vm-client.types.d.ts +14 -2
|
@@ -9,7 +9,6 @@ exports.convertExecutorToOrigin = convertExecutorToOrigin;
|
|
|
9
9
|
exports.deriveSvmCeaPda = deriveSvmCeaPda;
|
|
10
10
|
exports.deriveExecutorAccount = deriveExecutorAccount;
|
|
11
11
|
exports.resolveControllerAccount = resolveControllerAccount;
|
|
12
|
-
const tslib_1 = require("tslib");
|
|
13
12
|
const viem_1 = require("viem");
|
|
14
13
|
const web3_js_1 = require("@solana/web3.js");
|
|
15
14
|
const chain_1 = require("../../constants/chain");
|
|
@@ -44,7 +43,7 @@ function formatAddress(chain, address) {
|
|
|
44
43
|
try {
|
|
45
44
|
return (0, viem_1.getAddress)(address.toLowerCase());
|
|
46
45
|
}
|
|
47
|
-
catch
|
|
46
|
+
catch {
|
|
48
47
|
throw new Error('Invalid EVM address format');
|
|
49
48
|
}
|
|
50
49
|
}
|
|
@@ -111,9 +110,8 @@ function toChainAgnostic(address, options) {
|
|
|
111
110
|
* // → { chain: CHAIN.ETHEREUM_SEPOLIA, address: '0xabc...' }
|
|
112
111
|
*/
|
|
113
112
|
function fromChainAgnostic(caip) {
|
|
114
|
-
var _a, _b;
|
|
115
113
|
const [namespace, chainId, rawAddress] = caip.split(':');
|
|
116
|
-
const chain = (
|
|
114
|
+
const chain = (Object.entries(chain_1.CHAIN_INFO).find(([, info]) => info.chainId === chainId && chain_1.VM_NAMESPACE[info.vm] === namespace)?.[0] ?? null);
|
|
117
115
|
if (!chain) {
|
|
118
116
|
throw new Error(`Unsupported or unknown CAIP address: ${caip}`);
|
|
119
117
|
}
|
|
@@ -166,111 +164,109 @@ let _convertOriginToExecutorWarned = false;
|
|
|
166
164
|
* @deprecated Use `deriveExecutorAccount()` instead, which accepts a CAIP-10
|
|
167
165
|
* string and uses `options.chain` to control UEA vs CEA derivation.
|
|
168
166
|
*/
|
|
169
|
-
function convertOriginToExecutor(
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
if
|
|
179
|
-
|
|
180
|
-
let ueaAddress;
|
|
181
|
-
if (isPushChain(chain)) {
|
|
182
|
-
ueaAddress = address;
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
// Compute UEA from origin account
|
|
186
|
-
const ueaResult = yield convertOriginToExecutor(account, {
|
|
187
|
-
onlyCompute: false,
|
|
188
|
-
});
|
|
189
|
-
ueaAddress = ueaResult.address;
|
|
190
|
-
}
|
|
191
|
-
// Get CEA on the target external chain
|
|
192
|
-
const { cea, isDeployed } = yield (0, cea_utils_1.getCEAAddress)(ueaAddress, options.chain);
|
|
193
|
-
if (options.onlyCompute) {
|
|
194
|
-
return { address: cea, deployed: isDeployed };
|
|
195
|
-
}
|
|
196
|
-
return { address: cea };
|
|
197
|
-
}
|
|
167
|
+
async function convertOriginToExecutor(account, options = { onlyCompute: true }) {
|
|
168
|
+
if (!_convertOriginToExecutorWarned) {
|
|
169
|
+
console.warn('[PushChain] convertOriginToExecutor() is deprecated. Use deriveExecutorAccount() instead.');
|
|
170
|
+
_convertOriginToExecutorWarned = true;
|
|
171
|
+
}
|
|
172
|
+
const { chain, address } = account;
|
|
173
|
+
const { vm, chainId } = chain_1.CHAIN_INFO[chain];
|
|
174
|
+
// If target chain is external, compute CEA on that chain
|
|
175
|
+
if (options.chain && !isPushChain(options.chain)) {
|
|
176
|
+
// Get UEA first — if input is already on Push chain, use directly
|
|
177
|
+
let ueaAddress;
|
|
198
178
|
if (isPushChain(chain)) {
|
|
199
|
-
|
|
200
|
-
return { address: account.address, deployed: false };
|
|
201
|
-
}
|
|
202
|
-
return { address: account.address };
|
|
203
|
-
}
|
|
204
|
-
// Determine Push Network from the chain
|
|
205
|
-
const pushNetwork = getPushNetworkFromChain(chain);
|
|
206
|
-
// Check cache for computed address
|
|
207
|
-
const cachedAddress = accountCache.get(cache_1.CacheKeys.ueaAddressOnchain(chain, address, pushNetwork, vm));
|
|
208
|
-
if (cachedAddress) {
|
|
209
|
-
if (options.onlyCompute) {
|
|
210
|
-
// Check cache for deployment status
|
|
211
|
-
const cachedDeploymentStatus = accountCache.get(cache_1.CacheKeys.deploymentStatus(cachedAddress));
|
|
212
|
-
if (cachedDeploymentStatus !== null) {
|
|
213
|
-
return {
|
|
214
|
-
address: cachedAddress,
|
|
215
|
-
deployed: cachedDeploymentStatus,
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
else {
|
|
220
|
-
return { address: cachedAddress };
|
|
221
|
-
}
|
|
179
|
+
ueaAddress = address;
|
|
222
180
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
181
|
+
else {
|
|
182
|
+
// Compute UEA from origin account
|
|
183
|
+
const ueaResult = await convertOriginToExecutor(account, {
|
|
184
|
+
onlyCompute: false,
|
|
185
|
+
});
|
|
186
|
+
ueaAddress = ueaResult.address;
|
|
226
187
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
188
|
+
// Get CEA on the target external chain
|
|
189
|
+
const { cea, isDeployed } = await (0, cea_utils_1.getCEAAddress)(ueaAddress, options.chain);
|
|
190
|
+
if (options.onlyCompute) {
|
|
191
|
+
return { address: cea, deployed: isDeployed };
|
|
230
192
|
}
|
|
231
|
-
|
|
232
|
-
|
|
193
|
+
return { address: cea };
|
|
194
|
+
}
|
|
195
|
+
if (isPushChain(chain)) {
|
|
196
|
+
if (options.onlyCompute) {
|
|
197
|
+
return { address: account.address, deployed: false };
|
|
233
198
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
abi: factoryV1_1.FACTORY_V1,
|
|
242
|
-
functionName: 'computeUEA',
|
|
243
|
-
args: [
|
|
244
|
-
{
|
|
245
|
-
chainNamespace: chain_1.VM_NAMESPACE[vm],
|
|
246
|
-
chainId: chainId,
|
|
247
|
-
/**
|
|
248
|
-
* @dev - OwnerKey should be in bytes
|
|
249
|
-
* for eth - convert hex to bytes
|
|
250
|
-
* for sol - convert base64 to bytes
|
|
251
|
-
* for others - not defined yet
|
|
252
|
-
*/
|
|
253
|
-
owner: vm === enums_1.VM.EVM
|
|
254
|
-
? address
|
|
255
|
-
: vm === enums_1.VM.SVM
|
|
256
|
-
? (0, viem_1.bytesToHex)(Uint8Array.from(bs58_1.bs58.decode(address)))
|
|
257
|
-
: address,
|
|
258
|
-
},
|
|
259
|
-
],
|
|
260
|
-
});
|
|
261
|
-
// Cache the computed address
|
|
262
|
-
accountCache.set(cache_1.CacheKeys.ueaAddressOnchain(chain, address, pushNetwork, vm), computedAddress);
|
|
263
|
-
const byteCode = yield pushClient.publicClient.getCode({
|
|
264
|
-
address: computedAddress,
|
|
265
|
-
});
|
|
266
|
-
const isDeployed = byteCode !== undefined;
|
|
267
|
-
// Cache the deployment status
|
|
268
|
-
accountCache.set(cache_1.CacheKeys.deploymentStatus(computedAddress), isDeployed);
|
|
199
|
+
return { address: account.address };
|
|
200
|
+
}
|
|
201
|
+
// Determine Push Network from the chain
|
|
202
|
+
const pushNetwork = getPushNetworkFromChain(chain);
|
|
203
|
+
// Check cache for computed address
|
|
204
|
+
const cachedAddress = accountCache.get(cache_1.CacheKeys.ueaAddressOnchain(chain, address, pushNetwork, vm));
|
|
205
|
+
if (cachedAddress) {
|
|
269
206
|
if (options.onlyCompute) {
|
|
270
|
-
|
|
207
|
+
// Check cache for deployment status
|
|
208
|
+
const cachedDeploymentStatus = accountCache.get(cache_1.CacheKeys.deploymentStatus(cachedAddress));
|
|
209
|
+
if (cachedDeploymentStatus !== null) {
|
|
210
|
+
return {
|
|
211
|
+
address: cachedAddress,
|
|
212
|
+
deployed: cachedDeploymentStatus,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
271
215
|
}
|
|
272
|
-
|
|
216
|
+
else {
|
|
217
|
+
return { address: cachedAddress };
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
let pushChain;
|
|
221
|
+
if (pushNetwork === enums_1.PUSH_NETWORK.MAINNET) {
|
|
222
|
+
pushChain = enums_1.CHAIN.PUSH_MAINNET;
|
|
223
|
+
}
|
|
224
|
+
else if (pushNetwork === enums_1.PUSH_NETWORK.TESTNET_DONUT ||
|
|
225
|
+
pushNetwork === enums_1.PUSH_NETWORK.TESTNET) {
|
|
226
|
+
pushChain = enums_1.CHAIN.PUSH_TESTNET_DONUT;
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
pushChain = enums_1.CHAIN.PUSH_LOCALNET;
|
|
230
|
+
}
|
|
231
|
+
// Create PushClient to get factory address
|
|
232
|
+
const pushClient = new push_client_1.PushClient({
|
|
233
|
+
rpcUrls: chain_1.CHAIN_INFO[pushChain].defaultRPC,
|
|
234
|
+
network: pushNetwork,
|
|
235
|
+
});
|
|
236
|
+
const computedAddress = await pushClient.readContract({
|
|
237
|
+
address: pushClient.pushChainInfo.factoryAddress,
|
|
238
|
+
abi: factoryV1_1.FACTORY_V1,
|
|
239
|
+
functionName: 'computeUEA',
|
|
240
|
+
args: [
|
|
241
|
+
{
|
|
242
|
+
chainNamespace: chain_1.VM_NAMESPACE[vm],
|
|
243
|
+
chainId: chainId,
|
|
244
|
+
/**
|
|
245
|
+
* @dev - OwnerKey should be in bytes
|
|
246
|
+
* for eth - convert hex to bytes
|
|
247
|
+
* for sol - convert base64 to bytes
|
|
248
|
+
* for others - not defined yet
|
|
249
|
+
*/
|
|
250
|
+
owner: vm === enums_1.VM.EVM
|
|
251
|
+
? address
|
|
252
|
+
: vm === enums_1.VM.SVM
|
|
253
|
+
? (0, viem_1.bytesToHex)(Uint8Array.from(bs58_1.bs58.decode(address)))
|
|
254
|
+
: address,
|
|
255
|
+
},
|
|
256
|
+
],
|
|
273
257
|
});
|
|
258
|
+
// Cache the computed address
|
|
259
|
+
accountCache.set(cache_1.CacheKeys.ueaAddressOnchain(chain, address, pushNetwork, vm), computedAddress);
|
|
260
|
+
const byteCode = await pushClient.publicClient.getCode({
|
|
261
|
+
address: computedAddress,
|
|
262
|
+
});
|
|
263
|
+
const isDeployed = byteCode !== undefined;
|
|
264
|
+
// Cache the deployment status
|
|
265
|
+
accountCache.set(cache_1.CacheKeys.deploymentStatus(computedAddress), isDeployed);
|
|
266
|
+
if (options.onlyCompute) {
|
|
267
|
+
return { address: computedAddress, deployed: isDeployed };
|
|
268
|
+
}
|
|
269
|
+
return { address: computedAddress };
|
|
274
270
|
}
|
|
275
271
|
/**
|
|
276
272
|
* Convert Executor to Origin Account
|
|
@@ -282,43 +278,40 @@ function convertOriginToExecutor(account_1) {
|
|
|
282
278
|
* UEA and CEA lookups via the optional `options.chain` parameter.
|
|
283
279
|
*/
|
|
284
280
|
let _convertExecutorToOriginAccountWarned = false;
|
|
285
|
-
function convertExecutorToOriginAccount(ueaAddress, options) {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
chain: (0, chain_1.getPushViemChain)(pushChainKey),
|
|
298
|
-
transport: (0, viem_1.http)(RPC_URL),
|
|
299
|
-
});
|
|
300
|
-
const originResult = (yield client.readContract({
|
|
301
|
-
address: FACTORY_ADDRESS,
|
|
302
|
-
abi: factoryV1_1.FACTORY_V1,
|
|
303
|
-
functionName: 'getOriginForUEA',
|
|
304
|
-
args: [ueaAddress],
|
|
305
|
-
}));
|
|
306
|
-
const [account, isUEA] = originResult;
|
|
307
|
-
if (account.chainNamespace === '' ||
|
|
308
|
-
account.chainId === '' ||
|
|
309
|
-
account.owner === '0x') {
|
|
310
|
-
return { account: null, exists: isUEA };
|
|
311
|
-
}
|
|
312
|
-
const universalAccount = push_chain_1.PushChain.utils.account.fromChainAgnostic(`${account.chainNamespace}:${account.chainId}:${account.owner}`);
|
|
313
|
-
if (isUEA) {
|
|
314
|
-
if (universalAccount.chain.startsWith(chain_1.VM_NAMESPACE[enums_1.VM.SVM])) {
|
|
315
|
-
// Convert hex-encoded owner to base58 address format
|
|
316
|
-
const hexBytes = (0, viem_1.hexToBytes)(account.owner);
|
|
317
|
-
universalAccount.address = bs58_1.bs58.encode(Buffer.from(hexBytes));
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
return { account: universalAccount, exists: isUEA };
|
|
281
|
+
async function convertExecutorToOriginAccount(ueaAddress, options) {
|
|
282
|
+
if (!_convertExecutorToOriginAccountWarned) {
|
|
283
|
+
console.warn('[PushChain] convertExecutorToOriginAccount() is deprecated. Use resolveControllerAccount() instead.');
|
|
284
|
+
_convertExecutorToOriginAccountWarned = true;
|
|
285
|
+
}
|
|
286
|
+
const pushChainKey = pushNetworkToChainKey(options?.network ?? enums_1.PUSH_NETWORK.TESTNET_DONUT);
|
|
287
|
+
const RPC_URL = chain_1.PUSH_CHAIN_INFO[pushChainKey].defaultRPC[0];
|
|
288
|
+
const FACTORY_ADDRESS = chain_1.PUSH_CHAIN_INFO[pushChainKey].factoryAddress;
|
|
289
|
+
// Create viem public client
|
|
290
|
+
const client = (0, viem_1.createPublicClient)({
|
|
291
|
+
chain: (0, chain_1.getPushViemChain)(pushChainKey),
|
|
292
|
+
transport: (0, viem_1.http)(RPC_URL),
|
|
321
293
|
});
|
|
294
|
+
const originResult = (await client.readContract({
|
|
295
|
+
address: FACTORY_ADDRESS,
|
|
296
|
+
abi: factoryV1_1.FACTORY_V1,
|
|
297
|
+
functionName: 'getOriginForUEA',
|
|
298
|
+
args: [ueaAddress],
|
|
299
|
+
}));
|
|
300
|
+
const [account, isUEA] = originResult;
|
|
301
|
+
if (account.chainNamespace === '' ||
|
|
302
|
+
account.chainId === '' ||
|
|
303
|
+
account.owner === '0x') {
|
|
304
|
+
return { account: null, exists: isUEA };
|
|
305
|
+
}
|
|
306
|
+
const universalAccount = push_chain_1.PushChain.utils.account.fromChainAgnostic(`${account.chainNamespace}:${account.chainId}:${account.owner}`);
|
|
307
|
+
if (isUEA) {
|
|
308
|
+
if (universalAccount.chain.startsWith(chain_1.VM_NAMESPACE[enums_1.VM.SVM])) {
|
|
309
|
+
// Convert hex-encoded owner to base58 address format
|
|
310
|
+
const hexBytes = (0, viem_1.hexToBytes)(account.owner);
|
|
311
|
+
universalAccount.address = bs58_1.bs58.encode(Buffer.from(hexBytes));
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
return { account: universalAccount, exists: isUEA };
|
|
322
315
|
}
|
|
323
316
|
/**
|
|
324
317
|
* Convert Executor to Origin Account (with optional chain context)
|
|
@@ -332,80 +325,77 @@ function convertExecutorToOriginAccount(ueaAddress, options) {
|
|
|
332
325
|
* string and supports both UEA and CEA lookups via `options.chain`.
|
|
333
326
|
*/
|
|
334
327
|
let _convertExecutorToOriginWarned = false;
|
|
335
|
-
function convertExecutorToOrigin(executorAddress, options) {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
'0x0000000000000000000000000000000000000000') {
|
|
347
|
-
return { account: null, exists: false };
|
|
348
|
-
}
|
|
349
|
-
// Determine Push Chain from the external chain's network
|
|
350
|
-
const pushNetwork = getPushNetworkFromChain(options.chain);
|
|
351
|
-
let pushChain;
|
|
352
|
-
if (pushNetwork === enums_1.PUSH_NETWORK.MAINNET) {
|
|
353
|
-
pushChain = enums_1.CHAIN.PUSH_MAINNET;
|
|
354
|
-
}
|
|
355
|
-
else if (pushNetwork === enums_1.PUSH_NETWORK.TESTNET_DONUT ||
|
|
356
|
-
pushNetwork === enums_1.PUSH_NETWORK.TESTNET) {
|
|
357
|
-
pushChain = enums_1.CHAIN.PUSH_TESTNET_DONUT;
|
|
358
|
-
}
|
|
359
|
-
else {
|
|
360
|
-
pushChain = enums_1.CHAIN.PUSH_LOCALNET;
|
|
361
|
-
}
|
|
362
|
-
return {
|
|
363
|
-
account: {
|
|
364
|
-
chain: pushChain,
|
|
365
|
-
address: pushAccountAddress,
|
|
366
|
-
},
|
|
367
|
-
exists: true,
|
|
368
|
-
};
|
|
328
|
+
async function convertExecutorToOrigin(executorAddress, options) {
|
|
329
|
+
if (!options?._internal && !_convertExecutorToOriginWarned) {
|
|
330
|
+
console.warn('[PushChain] convertExecutorToOrigin() is deprecated. Use resolveControllerAccount() instead.');
|
|
331
|
+
_convertExecutorToOriginWarned = true;
|
|
332
|
+
}
|
|
333
|
+
if (options?.chain && !isPushChain(options.chain)) {
|
|
334
|
+
// CEA on external chain → look up PushAccount (UEA) on Push Chain
|
|
335
|
+
const pushAccountAddress = await (0, cea_utils_1.getPushAccountForCEA)(executorAddress, options.chain);
|
|
336
|
+
if (pushAccountAddress ===
|
|
337
|
+
'0x0000000000000000000000000000000000000000') {
|
|
338
|
+
return { account: null, exists: false };
|
|
369
339
|
}
|
|
370
|
-
//
|
|
371
|
-
const
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
return cached;
|
|
340
|
+
// Determine Push Chain from the external chain's network
|
|
341
|
+
const pushNetwork = getPushNetworkFromChain(options.chain);
|
|
342
|
+
let pushChain;
|
|
343
|
+
if (pushNetwork === enums_1.PUSH_NETWORK.MAINNET) {
|
|
344
|
+
pushChain = enums_1.CHAIN.PUSH_MAINNET;
|
|
376
345
|
}
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
const client = (0, viem_1.createPublicClient)({
|
|
381
|
-
chain: (0, chain_1.getPushViemChain)(pushChainKey),
|
|
382
|
-
transport: (0, viem_1.http)(RPC_URL),
|
|
383
|
-
});
|
|
384
|
-
const originResult = (yield client.readContract({
|
|
385
|
-
address: FACTORY_ADDRESS,
|
|
386
|
-
abi: factoryV1_1.FACTORY_V1,
|
|
387
|
-
functionName: 'getOriginForUEA',
|
|
388
|
-
args: [executorAddress],
|
|
389
|
-
}));
|
|
390
|
-
const [account, isUEA] = originResult;
|
|
391
|
-
if (account.chainNamespace === '' ||
|
|
392
|
-
account.chainId === '' ||
|
|
393
|
-
account.owner === '0x') {
|
|
394
|
-
const result = { account: null, exists: isUEA };
|
|
395
|
-
executorToOriginCache.set(cacheKey, result);
|
|
396
|
-
return result;
|
|
346
|
+
else if (pushNetwork === enums_1.PUSH_NETWORK.TESTNET_DONUT ||
|
|
347
|
+
pushNetwork === enums_1.PUSH_NETWORK.TESTNET) {
|
|
348
|
+
pushChain = enums_1.CHAIN.PUSH_TESTNET_DONUT;
|
|
397
349
|
}
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
if (universalAccount.chain.startsWith(chain_1.VM_NAMESPACE[enums_1.VM.SVM])) {
|
|
401
|
-
const hexBytes = (0, viem_1.hexToBytes)(account.owner);
|
|
402
|
-
universalAccount.address = bs58_1.bs58.encode(Buffer.from(hexBytes));
|
|
403
|
-
}
|
|
350
|
+
else {
|
|
351
|
+
pushChain = enums_1.CHAIN.PUSH_LOCALNET;
|
|
404
352
|
}
|
|
405
|
-
|
|
353
|
+
return {
|
|
354
|
+
account: {
|
|
355
|
+
chain: pushChain,
|
|
356
|
+
address: pushAccountAddress,
|
|
357
|
+
},
|
|
358
|
+
exists: true,
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
// Default: UEA on Push Chain → origin account
|
|
362
|
+
const network = options?.network ?? enums_1.PUSH_NETWORK.TESTNET_DONUT;
|
|
363
|
+
const cacheKey = `${executorAddress.toLowerCase()}:${network}`;
|
|
364
|
+
const cached = executorToOriginCache.get(cacheKey);
|
|
365
|
+
if (cached) {
|
|
366
|
+
return cached;
|
|
367
|
+
}
|
|
368
|
+
const pushChainKey = pushNetworkToChainKey(network);
|
|
369
|
+
const RPC_URL = chain_1.PUSH_CHAIN_INFO[pushChainKey].defaultRPC[0];
|
|
370
|
+
const FACTORY_ADDRESS = chain_1.PUSH_CHAIN_INFO[pushChainKey].factoryAddress;
|
|
371
|
+
const client = (0, viem_1.createPublicClient)({
|
|
372
|
+
chain: (0, chain_1.getPushViemChain)(pushChainKey),
|
|
373
|
+
transport: (0, viem_1.http)(RPC_URL),
|
|
374
|
+
});
|
|
375
|
+
const originResult = (await client.readContract({
|
|
376
|
+
address: FACTORY_ADDRESS,
|
|
377
|
+
abi: factoryV1_1.FACTORY_V1,
|
|
378
|
+
functionName: 'getOriginForUEA',
|
|
379
|
+
args: [executorAddress],
|
|
380
|
+
}));
|
|
381
|
+
const [account, isUEA] = originResult;
|
|
382
|
+
if (account.chainNamespace === '' ||
|
|
383
|
+
account.chainId === '' ||
|
|
384
|
+
account.owner === '0x') {
|
|
385
|
+
const result = { account: null, exists: isUEA };
|
|
406
386
|
executorToOriginCache.set(cacheKey, result);
|
|
407
387
|
return result;
|
|
408
|
-
}
|
|
388
|
+
}
|
|
389
|
+
const universalAccount = push_chain_1.PushChain.utils.account.fromChainAgnostic(`${account.chainNamespace}:${account.chainId}:${account.owner}`);
|
|
390
|
+
if (isUEA) {
|
|
391
|
+
if (universalAccount.chain.startsWith(chain_1.VM_NAMESPACE[enums_1.VM.SVM])) {
|
|
392
|
+
const hexBytes = (0, viem_1.hexToBytes)(account.owner);
|
|
393
|
+
universalAccount.address = bs58_1.bs58.encode(Buffer.from(hexBytes));
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
const result = { account: universalAccount, exists: isUEA };
|
|
397
|
+
executorToOriginCache.set(cacheKey, result);
|
|
398
|
+
return result;
|
|
409
399
|
}
|
|
410
400
|
/**
|
|
411
401
|
* Maps a PUSH_NETWORK to the corresponding Push Chain key for PUSH_CHAIN_INFO lookup.
|
|
@@ -474,103 +464,100 @@ function deriveSvmCeaPda(ueaAddress, targetChain, skipNetworkCheck) {
|
|
|
474
464
|
* @param options.skipNetworkCheck - If true, skip deployment check and return deployed: null.
|
|
475
465
|
* @returns The derived executor account address and deployment status.
|
|
476
466
|
*/
|
|
477
|
-
function deriveExecutorAccount(account, options) {
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
else {
|
|
494
|
-
// Compute UEA via factory contract
|
|
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
|
-
ueaAddress = 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(chain, address, pushNetwork, vm), ueaAddress);
|
|
518
|
-
}
|
|
519
|
-
// If target chain is external, derive CEA from the computed UEA
|
|
520
|
-
if (targetChain && !isPushChain(targetChain)) {
|
|
521
|
-
// SVM chains use PDA derivation, not CEAFactory
|
|
522
|
-
if (chain_1.CHAIN_INFO[targetChain].vm === enums_1.VM.SVM) {
|
|
523
|
-
return deriveSvmCeaPda(ueaAddress, targetChain, skipNetworkCheck);
|
|
524
|
-
}
|
|
525
|
-
const { cea, isDeployed } = yield (0, cea_utils_1.getCEAAddress)(ueaAddress, targetChain);
|
|
526
|
-
return { address: cea, deployed: skipNetworkCheck ? null : isDeployed };
|
|
527
|
-
}
|
|
528
|
-
// Return UEA with deployment check
|
|
529
|
-
if (skipNetworkCheck) {
|
|
530
|
-
return { address: ueaAddress, deployed: null };
|
|
531
|
-
}
|
|
467
|
+
async function deriveExecutorAccount(account, options) {
|
|
468
|
+
const skipNetworkCheck = options?.skipNetworkCheck ?? false;
|
|
469
|
+
const targetChain = options?.chain;
|
|
470
|
+
const { chain, address } = account;
|
|
471
|
+
// --- Case 1: Input is on an external chain ---
|
|
472
|
+
if (!isPushChain(chain)) {
|
|
473
|
+
const { vm, chainId } = chain_1.CHAIN_INFO[chain];
|
|
474
|
+
const pushNetwork = getPushNetworkFromChain(chain);
|
|
475
|
+
// Check cache for previously computed UEA
|
|
476
|
+
const cachedUea = accountCache.get(cache_1.CacheKeys.ueaAddressOnchain(chain, address, pushNetwork, vm));
|
|
477
|
+
let ueaAddress;
|
|
478
|
+
if (cachedUea) {
|
|
479
|
+
ueaAddress = cachedUea;
|
|
480
|
+
}
|
|
481
|
+
else {
|
|
482
|
+
// Compute UEA via factory contract
|
|
532
483
|
const pushChainKey = pushNetworkToChainKey(pushNetwork);
|
|
533
484
|
const pushClient = new push_client_1.PushClient({
|
|
534
485
|
rpcUrls: chain_1.CHAIN_INFO[pushChainKey].defaultRPC,
|
|
535
486
|
network: pushNetwork,
|
|
536
487
|
});
|
|
537
|
-
|
|
538
|
-
address:
|
|
488
|
+
ueaAddress = await pushClient.readContract({
|
|
489
|
+
address: pushClient.pushChainInfo.factoryAddress,
|
|
490
|
+
abi: factoryV1_1.FACTORY_V1,
|
|
491
|
+
functionName: 'computeUEA',
|
|
492
|
+
args: [
|
|
493
|
+
{
|
|
494
|
+
chainNamespace: chain_1.VM_NAMESPACE[vm],
|
|
495
|
+
chainId: chainId,
|
|
496
|
+
owner: vm === enums_1.VM.EVM
|
|
497
|
+
? address
|
|
498
|
+
: vm === enums_1.VM.SVM
|
|
499
|
+
? (0, viem_1.bytesToHex)(Uint8Array.from(bs58_1.bs58.decode(address)))
|
|
500
|
+
: address,
|
|
501
|
+
},
|
|
502
|
+
],
|
|
539
503
|
});
|
|
540
|
-
|
|
541
|
-
accountCache.set(cache_1.CacheKeys.
|
|
542
|
-
return { address: ueaAddress, deployed: isDeployed };
|
|
504
|
+
// Cache the computed address
|
|
505
|
+
accountCache.set(cache_1.CacheKeys.ueaAddressOnchain(chain, address, pushNetwork, vm), ueaAddress);
|
|
543
506
|
}
|
|
544
|
-
//
|
|
545
|
-
// If target chain is external, derive CEA
|
|
507
|
+
// If target chain is external, derive CEA from the computed UEA
|
|
546
508
|
if (targetChain && !isPushChain(targetChain)) {
|
|
547
509
|
// SVM chains use PDA derivation, not CEAFactory
|
|
548
510
|
if (chain_1.CHAIN_INFO[targetChain].vm === enums_1.VM.SVM) {
|
|
549
|
-
return deriveSvmCeaPda(
|
|
511
|
+
return deriveSvmCeaPda(ueaAddress, targetChain, skipNetworkCheck);
|
|
550
512
|
}
|
|
551
|
-
const { cea, isDeployed } =
|
|
513
|
+
const { cea, isDeployed } = await (0, cea_utils_1.getCEAAddress)(ueaAddress, targetChain);
|
|
552
514
|
return { address: cea, deployed: skipNetworkCheck ? null : isDeployed };
|
|
553
515
|
}
|
|
554
|
-
//
|
|
516
|
+
// Return UEA with deployment check
|
|
555
517
|
if (skipNetworkCheck) {
|
|
556
|
-
return { address:
|
|
518
|
+
return { address: ueaAddress, deployed: null };
|
|
557
519
|
}
|
|
558
|
-
const pushNetwork = targetChain && isPushChain(targetChain)
|
|
559
|
-
? getPushNetworkFromChain(targetChain)
|
|
560
|
-
: getPushNetworkFromChain(chain);
|
|
561
520
|
const pushChainKey = pushNetworkToChainKey(pushNetwork);
|
|
562
521
|
const pushClient = new push_client_1.PushClient({
|
|
563
522
|
rpcUrls: chain_1.CHAIN_INFO[pushChainKey].defaultRPC,
|
|
564
523
|
network: pushNetwork,
|
|
565
524
|
});
|
|
566
|
-
const byteCode =
|
|
567
|
-
address:
|
|
525
|
+
const byteCode = await pushClient.publicClient.getCode({
|
|
526
|
+
address: ueaAddress,
|
|
568
527
|
});
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
528
|
+
const isDeployed = byteCode !== undefined;
|
|
529
|
+
accountCache.set(cache_1.CacheKeys.deploymentStatus(ueaAddress), isDeployed);
|
|
530
|
+
return { address: ueaAddress, deployed: isDeployed };
|
|
531
|
+
}
|
|
532
|
+
// --- Case 2: Input is on Push Chain ---
|
|
533
|
+
// If target chain is external, derive CEA
|
|
534
|
+
if (targetChain && !isPushChain(targetChain)) {
|
|
535
|
+
// SVM chains use PDA derivation, not CEAFactory
|
|
536
|
+
if (chain_1.CHAIN_INFO[targetChain].vm === enums_1.VM.SVM) {
|
|
537
|
+
return deriveSvmCeaPda(address, targetChain, skipNetworkCheck);
|
|
538
|
+
}
|
|
539
|
+
const { cea, isDeployed } = await (0, cea_utils_1.getCEAAddress)(address, targetChain);
|
|
540
|
+
return { address: cea, deployed: skipNetworkCheck ? null : isDeployed };
|
|
541
|
+
}
|
|
542
|
+
// Push address, no external target — return with deployment check
|
|
543
|
+
if (skipNetworkCheck) {
|
|
544
|
+
return { address: address, deployed: null };
|
|
545
|
+
}
|
|
546
|
+
const pushNetwork = targetChain && isPushChain(targetChain)
|
|
547
|
+
? getPushNetworkFromChain(targetChain)
|
|
548
|
+
: getPushNetworkFromChain(chain);
|
|
549
|
+
const pushChainKey = pushNetworkToChainKey(pushNetwork);
|
|
550
|
+
const pushClient = new push_client_1.PushClient({
|
|
551
|
+
rpcUrls: chain_1.CHAIN_INFO[pushChainKey].defaultRPC,
|
|
552
|
+
network: pushNetwork,
|
|
573
553
|
});
|
|
554
|
+
const byteCode = await pushClient.publicClient.getCode({
|
|
555
|
+
address: address,
|
|
556
|
+
});
|
|
557
|
+
return {
|
|
558
|
+
address: address,
|
|
559
|
+
deployed: byteCode !== undefined,
|
|
560
|
+
};
|
|
574
561
|
}
|
|
575
562
|
/**
|
|
576
563
|
* Resolve the controller (origin) accounts for a given executor address.
|
|
@@ -583,73 +570,20 @@ function deriveExecutorAccount(account, options) {
|
|
|
583
570
|
* @param options.skipNetworkCheck - If true, skip existence checks, set exists: false
|
|
584
571
|
* @returns Resolved accounts in the controller chain
|
|
585
572
|
*/
|
|
586
|
-
function resolveControllerAccount(address, options) {
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
//
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
if (pushAccountAddress === '0x0000000000000000000000000000000000000000') {
|
|
596
|
-
return { accounts: [] };
|
|
597
|
-
}
|
|
598
|
-
// Determine Push Chain from external chain's network
|
|
599
|
-
const pushNetwork = getPushNetworkFromChain(inputChain);
|
|
600
|
-
const pushChainKey = pushNetworkToChainKey(pushNetwork);
|
|
601
|
-
// Now resolve UEA → origin
|
|
602
|
-
const pushChainId = pushChainKey;
|
|
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)({
|
|
606
|
-
chain: (0, chain_1.getPushViemChain)(pushChainKey),
|
|
607
|
-
transport: (0, viem_1.http)(RPC_URL),
|
|
608
|
-
});
|
|
609
|
-
const originResult = (yield client.readContract({
|
|
610
|
-
address: FACTORY_ADDRESS,
|
|
611
|
-
abi: factoryV1_1.FACTORY_V1,
|
|
612
|
-
functionName: 'getOriginForUEA',
|
|
613
|
-
args: [pushAccountAddress],
|
|
614
|
-
}));
|
|
615
|
-
const [originAccount, isUEA] = originResult;
|
|
616
|
-
const accounts = [];
|
|
617
|
-
// Add UEA entry
|
|
618
|
-
accounts.push({
|
|
619
|
-
chain: pushChainId,
|
|
620
|
-
chainName: getChainName(pushChainId),
|
|
621
|
-
address: pushAccountAddress,
|
|
622
|
-
type: 'uea',
|
|
623
|
-
exists: skipNetworkCheck ? false : true,
|
|
624
|
-
});
|
|
625
|
-
// Add origin (UOA) entry if found
|
|
626
|
-
if (isUEA &&
|
|
627
|
-
originAccount.chainNamespace !== '' &&
|
|
628
|
-
originAccount.chainId !== '' &&
|
|
629
|
-
originAccount.owner !== '0x') {
|
|
630
|
-
const originUniversal = fromChainAgnostic(`${originAccount.chainNamespace}:${originAccount.chainId}:${originAccount.owner}`);
|
|
631
|
-
// Handle SVM address conversion
|
|
632
|
-
let originAddress = originUniversal.address;
|
|
633
|
-
if (originUniversal.chain.startsWith(chain_1.VM_NAMESPACE[enums_1.VM.SVM])) {
|
|
634
|
-
const hexBytes = (0, viem_1.hexToBytes)(originAccount.owner);
|
|
635
|
-
originAddress = bs58_1.bs58.encode(Buffer.from(hexBytes));
|
|
636
|
-
}
|
|
637
|
-
accounts.push({
|
|
638
|
-
chain: originUniversal.chain,
|
|
639
|
-
chainName: getChainName(originUniversal.chain),
|
|
640
|
-
address: originAddress,
|
|
641
|
-
type: 'uoa',
|
|
642
|
-
exists: skipNetworkCheck ? false : true,
|
|
643
|
-
role: 'controller',
|
|
644
|
-
});
|
|
645
|
-
}
|
|
646
|
-
return { accounts };
|
|
573
|
+
async function resolveControllerAccount(address, options) {
|
|
574
|
+
const inputChain = options?.chain;
|
|
575
|
+
const skipNetworkCheck = options?.skipNetworkCheck ?? false;
|
|
576
|
+
// Case A: External chain → address is a CEA on that chain
|
|
577
|
+
if (inputChain && !isPushChain(inputChain)) {
|
|
578
|
+
// Look up UEA on Push Chain from CEA
|
|
579
|
+
const pushAccountAddress = await (0, cea_utils_1.getPushAccountForCEA)(address, inputChain);
|
|
580
|
+
if (pushAccountAddress === '0x0000000000000000000000000000000000000000') {
|
|
581
|
+
return { accounts: [] };
|
|
647
582
|
}
|
|
648
|
-
//
|
|
649
|
-
const pushNetwork =
|
|
650
|
-
? getPushNetworkFromChain(inputChain)
|
|
651
|
-
: enums_1.PUSH_NETWORK.TESTNET_DONUT;
|
|
583
|
+
// Determine Push Chain from external chain's network
|
|
584
|
+
const pushNetwork = getPushNetworkFromChain(inputChain);
|
|
652
585
|
const pushChainKey = pushNetworkToChainKey(pushNetwork);
|
|
586
|
+
// Now resolve UEA → origin
|
|
653
587
|
const pushChainId = pushChainKey;
|
|
654
588
|
const RPC_URL = chain_1.PUSH_CHAIN_INFO[pushChainKey].defaultRPC[0];
|
|
655
589
|
const FACTORY_ADDRESS = chain_1.PUSH_CHAIN_INFO[pushChainKey].factoryAddress;
|
|
@@ -657,14 +591,23 @@ function resolveControllerAccount(address, options) {
|
|
|
657
591
|
chain: (0, chain_1.getPushViemChain)(pushChainKey),
|
|
658
592
|
transport: (0, viem_1.http)(RPC_URL),
|
|
659
593
|
});
|
|
660
|
-
const originResult = (
|
|
594
|
+
const originResult = (await client.readContract({
|
|
661
595
|
address: FACTORY_ADDRESS,
|
|
662
596
|
abi: factoryV1_1.FACTORY_V1,
|
|
663
597
|
functionName: 'getOriginForUEA',
|
|
664
|
-
args: [
|
|
598
|
+
args: [pushAccountAddress],
|
|
665
599
|
}));
|
|
666
600
|
const [originAccount, isUEA] = originResult;
|
|
667
|
-
|
|
601
|
+
const accounts = [];
|
|
602
|
+
// Add UEA entry
|
|
603
|
+
accounts.push({
|
|
604
|
+
chain: pushChainId,
|
|
605
|
+
chainName: getChainName(pushChainId),
|
|
606
|
+
address: pushAccountAddress,
|
|
607
|
+
type: 'uea',
|
|
608
|
+
exists: skipNetworkCheck ? false : true,
|
|
609
|
+
});
|
|
610
|
+
// Add origin (UOA) entry if found
|
|
668
611
|
if (isUEA &&
|
|
669
612
|
originAccount.chainNamespace !== '' &&
|
|
670
613
|
originAccount.chainId !== '' &&
|
|
@@ -676,32 +619,73 @@ function resolveControllerAccount(address, options) {
|
|
|
676
619
|
const hexBytes = (0, viem_1.hexToBytes)(originAccount.owner);
|
|
677
620
|
originAddress = bs58_1.bs58.encode(Buffer.from(hexBytes));
|
|
678
621
|
}
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
622
|
+
accounts.push({
|
|
623
|
+
chain: originUniversal.chain,
|
|
624
|
+
chainName: getChainName(originUniversal.chain),
|
|
625
|
+
address: originAddress,
|
|
626
|
+
type: 'uoa',
|
|
627
|
+
exists: skipNetworkCheck ? false : true,
|
|
628
|
+
role: 'controller',
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
return { accounts };
|
|
632
|
+
}
|
|
633
|
+
// Case B: No chain or Push chain → address is a UEA or EOA on Push Chain
|
|
634
|
+
const pushNetwork = inputChain && isPushChain(inputChain)
|
|
635
|
+
? getPushNetworkFromChain(inputChain)
|
|
636
|
+
: enums_1.PUSH_NETWORK.TESTNET_DONUT;
|
|
637
|
+
const pushChainKey = pushNetworkToChainKey(pushNetwork);
|
|
638
|
+
const pushChainId = pushChainKey;
|
|
639
|
+
const RPC_URL = chain_1.PUSH_CHAIN_INFO[pushChainKey].defaultRPC[0];
|
|
640
|
+
const FACTORY_ADDRESS = chain_1.PUSH_CHAIN_INFO[pushChainKey].factoryAddress;
|
|
641
|
+
const client = (0, viem_1.createPublicClient)({
|
|
642
|
+
chain: (0, chain_1.getPushViemChain)(pushChainKey),
|
|
643
|
+
transport: (0, viem_1.http)(RPC_URL),
|
|
644
|
+
});
|
|
645
|
+
const originResult = (await client.readContract({
|
|
646
|
+
address: FACTORY_ADDRESS,
|
|
647
|
+
abi: factoryV1_1.FACTORY_V1,
|
|
648
|
+
functionName: 'getOriginForUEA',
|
|
649
|
+
args: [address],
|
|
650
|
+
}));
|
|
651
|
+
const [originAccount, isUEA] = originResult;
|
|
652
|
+
// If it's a UEA, resolve to origin
|
|
653
|
+
if (isUEA &&
|
|
654
|
+
originAccount.chainNamespace !== '' &&
|
|
655
|
+
originAccount.chainId !== '' &&
|
|
656
|
+
originAccount.owner !== '0x') {
|
|
657
|
+
const originUniversal = fromChainAgnostic(`${originAccount.chainNamespace}:${originAccount.chainId}:${originAccount.owner}`);
|
|
658
|
+
// Handle SVM address conversion
|
|
659
|
+
let originAddress = originUniversal.address;
|
|
660
|
+
if (originUniversal.chain.startsWith(chain_1.VM_NAMESPACE[enums_1.VM.SVM])) {
|
|
661
|
+
const hexBytes = (0, viem_1.hexToBytes)(originAccount.owner);
|
|
662
|
+
originAddress = bs58_1.bs58.encode(Buffer.from(hexBytes));
|
|
691
663
|
}
|
|
692
|
-
// Not a UEA — Push Chain EOA/smart contract, return as controller
|
|
693
664
|
return {
|
|
694
665
|
accounts: [
|
|
695
666
|
{
|
|
696
|
-
chain:
|
|
697
|
-
chainName: getChainName(
|
|
698
|
-
address:
|
|
667
|
+
chain: originUniversal.chain,
|
|
668
|
+
chainName: getChainName(originUniversal.chain),
|
|
669
|
+
address: originAddress,
|
|
699
670
|
type: 'uoa',
|
|
700
671
|
exists: skipNetworkCheck ? false : true,
|
|
701
672
|
role: 'controller',
|
|
702
673
|
},
|
|
703
674
|
],
|
|
704
675
|
};
|
|
705
|
-
}
|
|
676
|
+
}
|
|
677
|
+
// Not a UEA — Push Chain EOA/smart contract, return as controller
|
|
678
|
+
return {
|
|
679
|
+
accounts: [
|
|
680
|
+
{
|
|
681
|
+
chain: pushChainId,
|
|
682
|
+
chainName: getChainName(pushChainId),
|
|
683
|
+
address: address,
|
|
684
|
+
type: 'uoa',
|
|
685
|
+
exists: skipNetworkCheck ? false : true,
|
|
686
|
+
role: 'controller',
|
|
687
|
+
},
|
|
688
|
+
],
|
|
689
|
+
};
|
|
706
690
|
}
|
|
707
691
|
//# sourceMappingURL=account.js.map
|