@pushchain/core 5.1.2 → 5.1.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushchain/core",
3
- "version": "5.1.2",
3
+ "version": "5.1.3",
4
4
  "homepage": "https://push.org",
5
5
  "keywords": [
6
6
  "pushchain",
@@ -375,6 +375,11 @@ export declare class Orchestrator {
375
375
  * @returns Array of ProgressEvent objects to emit
376
376
  */
377
377
  private reconstructProgressEvents;
378
+ /**
379
+ * Detect the transaction route from UniversalTxV2 data.
380
+ * Used by trackTransaction to infer the route when it's not set by execute().
381
+ */
382
+ private detectRouteFromUniversalTxData;
378
383
  /**
379
384
  * Tracks a transaction by hash on Push Chain and returns UniversalTxResponse.
380
385
  * Reconstructs and replays SEND-TX-* progress events for completed transactions.
@@ -1010,7 +1010,9 @@ class Orchestrator {
1010
1010
  // passed as zeroAddress in the future.
1011
1011
  // execute.to = zeroAddress;
1012
1012
  payloadTo = viem_1.zeroAddress;
1013
- console.warn(`Multicalls should have execute.to as ${viem_1.zeroAddress}`);
1013
+ if (execute.to.toLowerCase() !== viem_1.zeroAddress) {
1014
+ console.warn(`Multicalls should have execute.to as ${viem_1.zeroAddress}`);
1015
+ }
1014
1016
  payloadData = this._buildMulticallPayloadData(execute.to, (0, payload_builders_1.buildExecuteMulticall)({ execute, ueaAddress: UEA }));
1015
1017
  req = this._buildUniversalTxRequest({
1016
1018
  recipient: viem_1.zeroAddress,
@@ -2431,16 +2433,18 @@ class Orchestrator {
2431
2433
  // Get UniversalGatewayPC address
2432
2434
  const gatewayPcAddress = this.getUniversalGatewayPCAddress();
2433
2435
  // Pre-fetch UEA status early — balance is needed for gas value calculation
2436
+ const signerChain = this.universalSigner.account.chain;
2437
+ const isNativePushEOA = this.isPushChain(signerChain);
2434
2438
  const [ueaCode, ueaBalance] = yield Promise.all([
2435
2439
  this.pushClient.publicClient.getCode({ address: ueaAddress }),
2436
2440
  this.pushClient.getBalance(ueaAddress),
2437
2441
  ]);
2438
- const isUEADeployed = ueaCode !== undefined;
2442
+ const isUEADeployed = isNativePushEOA || ueaCode !== undefined;
2439
2443
  if (!isUEADeployed) {
2440
2444
  throw new Error('UEA is not deployed. Please send an inbound transaction to Push Chain first ' +
2441
2445
  '(e.g. sendTransaction with value) to deploy your Universal Execution Account before using outbound transfers.');
2442
2446
  }
2443
- const ueaNonce = yield this.getUEANonce(ueaAddress);
2447
+ const ueaNonce = isNativePushEOA ? BigInt(0) : yield this.getUEANonce(ueaAddress);
2444
2448
  // Build the multicall that will execute ON Push Chain from UEA context
2445
2449
  // This includes: 1) approve PRC-20 (if needed), 2) call sendUniversalTxOutbound
2446
2450
  const pushChainMulticalls = [];
@@ -2626,16 +2630,18 @@ class Orchestrator {
2626
2630
  }, null, 2)}`);
2627
2631
  // --- Pre-fetch UEA status early — balance is needed for gas value calculation ---
2628
2632
  const gatewayPcAddress = this.getUniversalGatewayPCAddress();
2633
+ const signerChainSvm = this.universalSigner.account.chain;
2634
+ const isNativePushEOASvm = this.isPushChain(signerChainSvm);
2629
2635
  const [ueaCode, ueaBalance] = yield Promise.all([
2630
2636
  this.pushClient.publicClient.getCode({ address: ueaAddress }),
2631
2637
  this.pushClient.getBalance(ueaAddress),
2632
2638
  ]);
2633
- const isUEADeployed = ueaCode !== undefined;
2639
+ const isUEADeployed = isNativePushEOASvm || ueaCode !== undefined;
2634
2640
  if (!isUEADeployed) {
2635
2641
  throw new Error('UEA is not deployed. Please send an inbound transaction to Push Chain first ' +
2636
2642
  '(e.g. sendTransaction with value) to deploy your Universal Execution Account before using outbound transfers.');
2637
2643
  }
2638
- const ueaNonce = yield this.getUEANonce(ueaAddress);
2644
+ const ueaNonce = isNativePushEOASvm ? BigInt(0) : yield this.getUEANonce(ueaAddress);
2639
2645
  // --- Query gas fee (identical to EVM path) ---
2640
2646
  let gasFee = BigInt(0);
2641
2647
  let gasToken = selectors_1.ZERO_ADDRESS;
@@ -4312,18 +4318,46 @@ class Orchestrator {
4312
4318
  }
4313
4319
  // SEND_TX_07: Broadcasting (always emit)
4314
4320
  events.push(progress_hook_1.default[progress_hook_types_1.PROGRESS_HOOK.SEND_TX_07]());
4315
- // Determine outcome from pcTx status if available
4321
+ // Determine outcome from pcTx status and outbound status
4316
4322
  const pcTx = (_a = universalTxData === null || universalTxData === void 0 ? void 0 : universalTxData.pcTx) === null || _a === void 0 ? void 0 : _a[0];
4317
- const isFailed = (pcTx === null || pcTx === void 0 ? void 0 : pcTx.status) === 'FAILED';
4323
+ const isOutboundFailed = (universalTxData === null || universalTxData === void 0 ? void 0 : universalTxData.universalStatus) === types_1.UniversalTxStatus.OUTBOUND_FAILED;
4324
+ const isPcFailed = (pcTx === null || pcTx === void 0 ? void 0 : pcTx.status) === 'FAILED';
4325
+ const isFailed = isPcFailed || isOutboundFailed;
4318
4326
  // SEND_TX_99_01/02: Final outcome
4319
4327
  if (isFailed) {
4320
- events.push(progress_hook_1.default[progress_hook_types_1.PROGRESS_HOOK.SEND_TX_99_02]((pcTx === null || pcTx === void 0 ? void 0 : pcTx.errorMsg) || 'Unknown error'));
4328
+ const errorMsg = isOutboundFailed
4329
+ ? 'Outbound transaction failed (status: OUTBOUND_FAILED)'
4330
+ : ((pcTx === null || pcTx === void 0 ? void 0 : pcTx.errorMsg) || 'Unknown error');
4331
+ events.push(progress_hook_1.default[progress_hook_types_1.PROGRESS_HOOK.SEND_TX_99_02](errorMsg));
4321
4332
  }
4322
4333
  else {
4323
4334
  events.push(progress_hook_1.default[progress_hook_types_1.PROGRESS_HOOK.SEND_TX_99_01]([universalTxResponse]));
4324
4335
  }
4325
4336
  return events;
4326
4337
  }
4338
+ /**
4339
+ * Detect the transaction route from UniversalTxV2 data.
4340
+ * Used by trackTransaction to infer the route when it's not set by execute().
4341
+ */
4342
+ detectRouteFromUniversalTxData(universalTxData) {
4343
+ if (!universalTxData)
4344
+ return undefined;
4345
+ const hasOutbound = universalTxData.outboundTx.length > 0;
4346
+ const hasInbound = !!universalTxData.inboundTx;
4347
+ const statusIndicatesOutbound = [
4348
+ types_1.UniversalTxStatus.OUTBOUND_PENDING,
4349
+ types_1.UniversalTxStatus.OUTBOUND_SUCCESS,
4350
+ types_1.UniversalTxStatus.OUTBOUND_FAILED,
4351
+ ].includes(universalTxData.universalStatus);
4352
+ if (hasOutbound || statusIndicatesOutbound) {
4353
+ return hasInbound
4354
+ ? route_detector_1.TransactionRoute.CEA_TO_CEA
4355
+ : route_detector_1.TransactionRoute.UOA_TO_CEA;
4356
+ }
4357
+ if (hasInbound)
4358
+ return route_detector_1.TransactionRoute.CEA_TO_PUSH;
4359
+ return route_detector_1.TransactionRoute.UOA_TO_PUSH;
4360
+ }
4327
4361
  /**
4328
4362
  * Tracks a transaction by hash on Push Chain and returns UniversalTxResponse.
4329
4363
  * Reconstructs and replays SEND-TX-* progress events for completed transactions.
@@ -4380,20 +4414,53 @@ class Orchestrator {
4380
4414
  }
4381
4415
  // Try to get UniversalTx data for richer progress reconstruction
4382
4416
  // (may not exist for direct Push Chain transactions)
4417
+ // Three-tier lookup: direct hash → computed keccak ID → Cosmos event extraction
4383
4418
  let universalTxData;
4384
4419
  try {
4385
- // Attempt to find UniversalTx by searching pcTx entries
4386
- // For now, we'll try to look up by the tx hash
4387
4420
  const utxResponse = yield this.pushClient.getUniversalTxByIdV2(txHash);
4388
4421
  if (utxResponse === null || utxResponse === void 0 ? void 0 : utxResponse.universalTx) {
4389
4422
  universalTxData = utxResponse.universalTx;
4390
4423
  }
4391
4424
  }
4392
4425
  catch (_a) {
4393
- // Ignore - direct Push Chain tx or tx not indexed yet
4426
+ // Ignore - try computed ID next
4427
+ }
4428
+ if (!universalTxData) {
4429
+ try {
4430
+ const computedId = this.computeUniversalTxId(txHash);
4431
+ const queryId = computedId.startsWith('0x') ? computedId.slice(2) : computedId;
4432
+ const utxResponse = yield this.pushClient.getUniversalTxByIdV2(queryId);
4433
+ if (utxResponse === null || utxResponse === void 0 ? void 0 : utxResponse.universalTx) {
4434
+ universalTxData = utxResponse.universalTx;
4435
+ }
4436
+ }
4437
+ catch (_b) {
4438
+ // Ignore - try Cosmos event extraction next
4439
+ }
4440
+ }
4441
+ if (!universalTxData) {
4442
+ try {
4443
+ const extractedId = yield this.extractUniversalSubTxIdFromTx(txHash);
4444
+ if (extractedId) {
4445
+ const queryId = extractedId.startsWith('0x') ? extractedId.slice(2) : extractedId;
4446
+ const utxResponse = yield this.pushClient.getUniversalTxByIdV2(queryId);
4447
+ if (utxResponse === null || utxResponse === void 0 ? void 0 : utxResponse.universalTx) {
4448
+ universalTxData = utxResponse.universalTx;
4449
+ }
4450
+ }
4451
+ }
4452
+ catch (_c) {
4453
+ // Ignore - no universal tx data available
4454
+ }
4394
4455
  }
4395
4456
  // Transform to UniversalTxResponse
4396
4457
  const universalTxResponse = yield this.transformToUniversalTxResponse(tx, eventBuffer);
4458
+ // Detect route from UniversalTxV2 data and set on response
4459
+ // This enables wait() to trigger outbound polling via waitForOutboundTx()
4460
+ const detectedRoute = this.detectRouteFromUniversalTxData(universalTxData);
4461
+ if (detectedRoute) {
4462
+ universalTxResponse.route = detectedRoute;
4463
+ }
4397
4464
  // Reconstruct and emit SEND-TX-* progress events
4398
4465
  const reconstructedEvents = this.reconstructProgressEvents(universalTxResponse, universalTxData);
4399
4466
  for (const event of reconstructedEvents) {
@@ -5562,7 +5629,7 @@ class Orchestrator {
5562
5629
  let value;
5563
5630
  let data;
5564
5631
  let rawTransactionData;
5565
- const ueaOrigin = yield push_chain_1.PushChain.utils.account.convertExecutorToOriginAccount(tx.to);
5632
+ const ueaOrigin = yield push_chain_1.PushChain.utils.account.convertExecutorToOrigin(tx.to);
5566
5633
  let originAddress;
5567
5634
  if (ueaOrigin.exists) {
5568
5635
  if (!ueaOrigin.account) {
@@ -5760,9 +5827,11 @@ class Orchestrator {
5760
5827
  const receipt = yield tx.wait();
5761
5828
  baseReceipt = this.transformToUniversalTxReceipt(receipt, universalTxResponse);
5762
5829
  }
5763
- // If outbound route (Route 2: UOA → CEA, Route 3: CEA → Push), poll for external chain details
5764
- if (universalTxResponse.route === route_detector_1.TransactionRoute.UOA_TO_CEA ||
5765
- universalTxResponse.route === route_detector_1.TransactionRoute.CEA_TO_PUSH) {
5830
+ // If outbound route, poll for external chain details
5831
+ const routeInfo = universalTxResponse.route
5832
+ ? (0, route_detector_1.getRouteInfo)(universalTxResponse.route)
5833
+ : undefined;
5834
+ if (routeInfo === null || routeInfo === void 0 ? void 0 : routeInfo.isOutbound) {
5766
5835
  try {
5767
5836
  const outboundDetails = yield this.waitForOutboundTx(tx.hash, {
5768
5837
  initialWaitMs: Orchestrator.OUTBOUND_INITIAL_WAIT_MS,