@pushchain/core 6.0.5 → 6.0.7

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": "6.0.5",
3
+ "version": "6.0.7",
4
4
  "homepage": "https://push.org",
5
5
  "keywords": [
6
6
  "pushchain",
@@ -146,7 +146,9 @@ function buildHopDescriptor(ctx, params, route, ueaAddress) {
146
146
  case route_detector_1.TransactionRoute.UOA_TO_PUSH: {
147
147
  // Route 1: Build Push Chain multicalls
148
148
  const seedAmount = (_d = params.value) !== null && _d !== void 0 ? _d : BigInt(0);
149
- if (isValueOnlyNativeSeedToOwnUea(params, ueaAddress)) {
149
+ if (isValueOnlyNativeSeedToOwnUea(params, ueaAddress, {
150
+ allowFunds: true,
151
+ })) {
150
152
  return Object.assign(Object.assign({}, baseDescriptor), { pushMulticalls: [], nativeSeedOnly: true, nativeSeedAmount: seedAmount });
151
153
  }
152
154
  const executeParams = (0, helpers_1.toExecuteParams)(params);
@@ -643,14 +645,44 @@ function getSegmentType(route) {
643
645
  function sumMulticallNativeValue(multicalls) {
644
646
  return (multicalls !== null && multicalls !== void 0 ? multicalls : []).reduce((sum, mc) => { var _a; return sum + ((_a = mc.value) !== null && _a !== void 0 ? _a : BigInt(0)); }, BigInt(0));
645
647
  }
646
- function isValueOnlyNativeSeedToOwnUea(params, ueaAddress) {
648
+ function isValueOnlyNativeSeedToOwnUea(params, ueaAddress, options) {
647
649
  var _a, _b;
648
650
  return (((_a = params.value) !== null && _a !== void 0 ? _a : BigInt(0)) > BigInt(0) &&
649
- !((_b = params.funds) === null || _b === void 0 ? void 0 : _b.amount) &&
651
+ ((options === null || options === void 0 ? void 0 : options.allowFunds) === true || !((_b = params.funds) === null || _b === void 0 ? void 0 : _b.amount)) &&
650
652
  (0, data_utils_1.isEmptyPayloadData)(params.data) &&
651
653
  typeof params.to === 'string' &&
652
654
  params.to.toLowerCase() === ueaAddress.toLowerCase());
653
655
  }
656
+ function getRootFundsDeposit(hops) {
657
+ let rootFunds;
658
+ for (const hop of hops) {
659
+ // Only the leading Push execution segment is submitted through the root
660
+ // source-chain gateway tx. Later UOA_TO_PUSH hops may be nested inside a
661
+ // Route 3 child inbound and must not attach origin-chain funds to root.
662
+ if (hop.route !== 'UOA_TO_PUSH')
663
+ break;
664
+ const funds = hop.params.funds;
665
+ if (!(funds === null || funds === void 0 ? void 0 : funds.amount) || funds.amount <= BigInt(0))
666
+ continue;
667
+ if (!rootFunds) {
668
+ rootFunds = Object.assign({}, funds);
669
+ continue;
670
+ }
671
+ const currentToken = rootFunds.token;
672
+ const nextToken = funds.token;
673
+ const sameToken = currentToken === nextToken ||
674
+ (!!currentToken &&
675
+ !!nextToken &&
676
+ currentToken.address.toLowerCase() === nextToken.address.toLowerCase() &&
677
+ currentToken.symbol === nextToken.symbol &&
678
+ currentToken.mechanism === nextToken.mechanism);
679
+ if (!sameToken) {
680
+ throw new Error('Cascade can only bridge one origin token in root Push execution hops. Split mixed-token deposits into separate transactions.');
681
+ }
682
+ rootFunds = Object.assign(Object.assign({}, rootFunds), { amount: rootFunds.amount + funds.amount });
683
+ }
684
+ return rootFunds;
685
+ }
654
686
  function isNativeSeedOnlyHop(hop) {
655
687
  return (hop === null || hop === void 0 ? void 0 : hop.nativeSeedOnly) === true;
656
688
  }
@@ -1411,6 +1443,10 @@ function createCascadedBuilder(ctx, preparedTxs, callbacks, defaultEventHook) {
1411
1443
  value: cascadeRequiredNativeValue,
1412
1444
  data: composedMulticalls,
1413
1445
  };
1446
+ const rootFundsDeposit = getRootFundsDeposit(hops);
1447
+ if (rootFundsDeposit) {
1448
+ executeParams.funds = rootFundsDeposit;
1449
+ }
1414
1450
  const response = yield withMultihopRootProgressMapping(ctx, () => callbacks.executeFn(executeParams));
1415
1451
  // Build hop info for tracking
1416
1452
  const hopInfos = hops.map((hop, index) => ({
@@ -33,6 +33,7 @@ const svm_bridge_1 = require("./svm-bridge");
33
33
  const signing_1 = require("./signing");
34
34
  const quote_1 = require("./quote");
35
35
  const formatters_1 = require("../../formatters");
36
+ const helpers_1 = require("./helpers");
36
37
  function executeFundsWithPayload(ctx, execute, eventBuffer, getResponseCallbacks) {
37
38
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
38
39
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
@@ -111,6 +112,25 @@ function executeFundsWithPayload(ctx, execute, eventBuffer, getResponseCallbacks
111
112
  // Apply sizer floor: Case A pads to $1, Cases B/C pass-through.
112
113
  if (depositUsd < r1Sizing.paddedDepositUsd)
113
114
  depositUsd = r1Sizing.paddedDepositUsd;
115
+ // Match funds-only and standard fee-lock sizing: fixed PC→USD conversion can
116
+ // underfund large PC deposits when the live pETH/WPC pool has meaningful
117
+ // slippage. Quote the native amount required for the target WPC output and
118
+ // raise the USD deposit before converting back to source-chain native value.
119
+ if (chain_1.CHAIN_INFO[chain].vm === enums_1.VM.EVM && requiredFunds > ueaBalance) {
120
+ const deficit = requiredFunds - ueaBalance;
121
+ const targetWpc = (deficit * BigInt(12)) / BigInt(10);
122
+ const originPrc20 = (0, helpers_1.getNativePRC20ForChain)(chain, ctx.pushNetwork);
123
+ const poolNativeAmount = yield (0, gas_calculator_1.estimateNativeForDesiredDeposit)(ctx, targetWpc, originPrc20);
124
+ if (poolNativeAmount > BigInt(0)) {
125
+ const poolBasedUsd = (poolNativeAmount * nativeTokenUsdPrice) / oneNativeUnit;
126
+ if (poolBasedUsd > depositUsd) {
127
+ (0, context_1.printLog)(ctx, `sendFundsWithPayload — pool-based deposit sizing overrides fixed-rate estimate: ` +
128
+ `fixedUsd=${depositUsd.toString()}, poolBasedUsd=${poolBasedUsd.toString()}, ` +
129
+ `requiredFunds=${requiredFunds.toString()}, ueaBalance=${ueaBalance.toString()}`);
130
+ depositUsd = poolBasedUsd;
131
+ }
132
+ }
133
+ }
114
134
  // If SVM, clamp depositUsd to on-chain Config caps
115
135
  if (chain_1.CHAIN_INFO[chain].vm === enums_1.VM.SVM) {
116
136
  const svmClient = new svm_client_1.SvmClient({
@@ -35,6 +35,7 @@ function preflightSuffix(sufficient, pathTag, enforceGasCheck) {
35
35
  ? `INSUFFICIENT (${pathTag}); warning only, proceeding`
36
36
  : `INSUFFICIENT (${pathTag})`;
37
37
  }
38
+ const displayPathTag = (pathTag) => pathTag === 'CASCADE' ? 'MULTICHAIN' : pathTag;
38
39
  /**
39
40
  * Classify a sign-time error as either a true wallet user-decline
40
41
  * (viem `UserRejectedRequestError`, ethers `ACTION_REJECTED`, EIP-1193 4001,
@@ -275,14 +276,14 @@ const RAW_HOOKS_R1 = {
275
276
  },
276
277
  [progress_hook_types_1.PROGRESS_HOOK.SEND_TX_199_03]: (targetChain, elapsedMs) => ({
277
278
  id: progress_hook_types_1.PROGRESS_HOOK.SEND_TX_199_03,
278
- title: `Syncing State with ${friendlyChain(targetChain)} Timeout`,
279
- message: `Timed out waiting for UGPC relay to ${targetChain}`,
279
+ title: 'Syncing State with Push Chain Timeout',
280
+ message: 'Timed out waiting for relay to Push Chain',
280
281
  response: { error: 'relay timeout', chain: targetChain, elapsedMs },
281
282
  level: 'ERROR',
282
283
  }),
283
284
  [progress_hook_types_1.PROGRESS_HOOK.SEND_TX_199_99]: (txHash) => ({
284
285
  id: progress_hook_types_1.PROGRESS_HOOK.SEND_TX_199_99,
285
- title: 'Push Chain Tx Completed',
286
+ title: 'Intermediate Push Chain Tx Completed',
286
287
  message: `Intermediate Push Chain tx confirmed: ${txHash}, progressing to next phase`,
287
288
  response: { txHash },
288
289
  level: 'INFO',
@@ -340,7 +341,7 @@ const RAW_HOOKS_R2 = {
340
341
  const enforceGasCheck = extra === null || extra === void 0 ? void 0 : extra.enforceGasCheck;
341
342
  return {
342
343
  id: progress_hook_types_1.PROGRESS_HOOK.SEND_TX_203_03,
343
- title: 'Pre-flight Balance Check',
344
+ title: 'Checking Balance Requirements',
344
345
  message: `UEA balance: ${availableStr}; required: ${requiredStr}; ` +
345
346
  preflightSuffix(sufficient, pathTag, enforceGasCheck),
346
347
  response: {
@@ -471,7 +472,7 @@ const RAW_HOOKS_R2 = {
471
472
  }),
472
473
  [progress_hook_types_1.PROGRESS_HOOK.SEND_TX_299_99]: (targetChain, txHash) => ({
473
474
  id: progress_hook_types_1.PROGRESS_HOOK.SEND_TX_299_99,
474
- title: `${friendlyChain(targetChain)} Tx Completed`,
475
+ title: `Intermediate ${friendlyChain(targetChain)} Tx Completed`,
475
476
  message: `Intermediate ${friendlyChain(targetChain)} tx confirmed: ${txHash}, progressing to next phase`,
476
477
  response: { chain: targetChain, txHash },
477
478
  level: 'INFO',
@@ -551,7 +552,7 @@ const RAW_HOOKS_R3 = {
551
552
  const enforceGasCheck = extra === null || extra === void 0 ? void 0 : extra.enforceGasCheck;
552
553
  return {
553
554
  id: progress_hook_types_1.PROGRESS_HOOK.SEND_TX_303_04,
554
- title: 'Pre-flight Balance Check',
555
+ title: 'Checking Balance Requirements',
555
556
  message: `UEA balance: ${availableStr}; required: ${requiredStr}; ` +
556
557
  preflightSuffix(sufficient, pathTag, enforceGasCheck),
557
558
  response: {
@@ -712,11 +713,7 @@ const RAW_HOOKS_R3 = {
712
713
  },
713
714
  [progress_hook_types_1.PROGRESS_HOOK.SEND_TX_399_03]: (sourceChain, elapsedMs, phase = 'inbound') => ({
714
715
  id: progress_hook_types_1.PROGRESS_HOOK.SEND_TX_399_03,
715
- title: phase === 'outbound'
716
- ? `Syncing State with ${friendlyChain(sourceChain)} Timeout`
717
- : phase === 'push'
718
- ? 'Push Chain Tx Timeout'
719
- : 'Push Chain Inbound Timeout',
716
+ title: 'Push Chain Inbound Tx Timeout',
720
717
  message: phase === 'outbound'
721
718
  ? `Timed out waiting for ${friendlyChain(sourceChain)} relay`
722
719
  : phase === 'push'
@@ -736,8 +733,8 @@ const RAW_HOOKS_R3 = {
736
733
  }),
737
734
  [progress_hook_types_1.PROGRESS_HOOK.SEND_TX_399_99]: (sourceChain, txHash) => ({
738
735
  id: progress_hook_types_1.PROGRESS_HOOK.SEND_TX_399_99,
739
- title: `${friendlyChain(sourceChain)} Tx Completed`,
740
- message: `Intermediate ${friendlyChain(sourceChain)} tx confirmed: ${txHash}, progressing to next phase`,
736
+ title: `Intermediate ${friendlyChain(sourceChain)} to Push Tx Completed`,
737
+ message: `Intermediate ${friendlyChain(sourceChain)} to Push tx confirmed: ${txHash}, progressing to next phase`,
741
738
  response: { chain: sourceChain, txHash },
742
739
  level: 'INFO',
743
740
  }),
@@ -824,11 +821,12 @@ const RAW_HOOKS_MULTICHAIN = {
824
821
  const availableStr = kind === 'PRC20' ? `${available} units` : (0, formatters_1.formatPc)(available, 4);
825
822
  const requiredStr = kind === 'PRC20' ? `${required} units` : (0, formatters_1.formatPc)(required, 4);
826
823
  const enforceGasCheck = extra === null || extra === void 0 ? void 0 : extra.enforceGasCheck;
824
+ const visiblePathTag = displayPathTag(pathTag);
827
825
  return {
828
826
  id: progress_hook_types_1.PROGRESS_HOOK.SEND_TX_003_03,
829
- title: 'Cascade Pre-flight Balance Check',
827
+ title: 'Checking Balance Requirements',
830
828
  message: `UEA balance: ${availableStr}; required: ${requiredStr}; ` +
831
- preflightSuffix(sufficient, pathTag, enforceGasCheck),
829
+ preflightSuffix(sufficient, visiblePathTag, enforceGasCheck),
832
830
  response: {
833
831
  required,
834
832
  available,
@@ -849,13 +847,14 @@ const RAW_HOOKS_MULTICHAIN = {
849
847
  var _a, _b, _c, _d;
850
848
  const kind = (_a = extra === null || extra === void 0 ? void 0 : extra.kind) !== null && _a !== void 0 ? _a : 'NATIVE';
851
849
  const shortfallStr = kind === 'PRC20' ? `${shortfall} units` : (0, formatters_1.formatPc)(shortfall, 4);
850
+ const visiblePathTag = displayPathTag(pathTag);
852
851
  const remediation = kind === 'PRC20'
853
852
  ? `Bridge the burn token (${(_b = extra === null || extra === void 0 ? void 0 : extra.burnToken) !== null && _b !== void 0 ? _b : 'PRC-20'}) to UEA ${ueaAddress} before retrying.`
854
853
  : `Bridge >=${shortfallStr} to UEA ${ueaAddress} before retrying.`;
855
854
  return {
856
855
  id: progress_hook_types_1.PROGRESS_HOOK.SEND_TX_003_04,
857
- title: 'Cascade Insufficient UEA Balance',
858
- message: `Shortfall ${shortfallStr} on ${pathTag}. ${remediation}`,
856
+ title: 'Multichain Insufficient UEA Balance',
857
+ message: `Shortfall ${shortfallStr} on ${visiblePathTag}. ${remediation}`,
859
858
  response: {
860
859
  required,
861
860
  available,
@@ -871,9 +870,9 @@ const RAW_HOOKS_MULTICHAIN = {
871
870
  },
872
871
  [progress_hook_types_1.PROGRESS_HOOK.SEND_TX_003_05]: (quoted, threshold, gasToken, pathTag) => ({
873
872
  id: progress_hook_types_1.PROGRESS_HOOK.SEND_TX_003_05,
874
- title: 'Cascade SVM Native-Value Warn Threshold',
873
+ title: 'Multichain SVM Native-Value Warn Threshold',
875
874
  message: `Buffered pool quote ${(0, formatters_1.formatPc)(quoted, 4)} exceeds warn threshold ${(0, formatters_1.formatPc)(threshold, 4)} ` +
876
- `for ${gasToken} (${pathTag}). Pool may be skewed or quote is unusually large. ` +
875
+ `for ${gasToken} (${displayPathTag(pathTag)}). Pool may be skewed or quote is unusually large. ` +
877
876
  `No action taken — pre-flight will determine if balance covers it.`,
878
877
  response: { quoted, threshold, gasToken, pathTag },
879
878
  level: 'INFO',
@@ -888,15 +887,15 @@ const RAW_HOOKS_MULTICHAIN = {
888
887
  [progress_hook_types_1.PROGRESS_HOOK.SEND_TX_999_02]: (failedAt, total, errorMessage) => ({
889
888
  id: progress_hook_types_1.PROGRESS_HOOK.SEND_TX_999_02,
890
889
  title: 'Multichain Transactions Failed',
891
- message: `Cascade failed at hop ${failedAt} of ${total}: ${errorMessage}`,
890
+ message: `Multichain failed at hop ${failedAt} of ${total}: ${errorMessage}`,
892
891
  response: { failedAt, total, error: errorMessage },
893
892
  level: 'ERROR',
894
893
  }),
895
894
  [progress_hook_types_1.PROGRESS_HOOK.SEND_TX_999_03]: (failedAt, total) => ({
896
895
  id: progress_hook_types_1.PROGRESS_HOOK.SEND_TX_999_03,
897
896
  title: 'Multichain Transactions Timeout',
898
- message: `Cascade timed out at hop ${failedAt} of ${total}`,
899
- response: { failedAt, total, error: 'cascade timeout' },
897
+ message: `Multichain timed out at hop ${failedAt} of ${total}`,
898
+ response: { failedAt, total, error: 'multichain timeout' },
900
899
  level: 'ERROR',
901
900
  }),
902
901
  };