@pushchain/core 5.1.4-alpha.7 → 5.1.4-alpha.8

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.4-alpha.7",
3
+ "version": "5.1.4-alpha.8",
4
4
  "homepage": "https://push.org",
5
5
  "keywords": [
6
6
  "pushchain",
@@ -263,44 +263,56 @@ function executeUoaToCea(ctx, params, executeFn) {
263
263
  let gasFee = BigInt(0);
264
264
  let nativeValueForGas = BigInt(0);
265
265
  let gasToken = selectors_1.ZERO_ADDRESS;
266
+ let universalCoreAddress;
266
267
  if (prc20Token !== selectors_1.ZERO_ADDRESS) {
267
268
  try {
268
269
  const result = yield (0, gas_calculator_1.queryOutboundGasFee)(ctx, prc20Token, outboundReq.gasLimit);
269
270
  gasFee = result.gasFee;
270
271
  gasToken = result.gasToken;
271
272
  nativeValueForGas = result.nativeValueForGas;
273
+ universalCoreAddress = result.universalCoreAddress;
272
274
  (0, context_1.printLog)(ctx, `executeUoaToCea — queried gas fee: ${gasFee.toString()}, gasToken: ${gasToken}, nativeValueForGas: ${nativeValueForGas.toString()}`);
273
275
  }
274
276
  catch (err) {
275
277
  throw new Error(`Failed to query outbound gas fee: ${err}`);
276
278
  }
277
279
  }
278
- // Adjust nativeValueForGas: the 1Mx multiplier from queryOutboundGasFee produces
279
- // a value far too low for the actual WPC/gasToken swap price. Set it to 200 UPC
280
- // (capped by balance) — enough for the swap, but avoids draining thin pools.
281
- // The contract's swapAndBurnGas does exactOutputSingle and refunds excess PC.
280
+ // Estimate the actual WPC needed for the swap using on-chain pool price.
281
+ // The static 1Mx multiplier from queryOutboundGasFee doesn't reflect the real
282
+ // WPC/gasToken exchange rate. estimateNativeValueForSwap reads the Uniswap V3
283
+ // pool's slot0, computes the true cost, and adds a 2x buffer.
284
+ // This matches the SVM path (executeUoaToCeaSvm) which already uses this.
285
+ // Excess msg.value is refunded by the contract's swapAndBurnGas.
286
+ if (universalCoreAddress && gasFee > BigInt(0)) {
287
+ const estimated = yield (0, gas_calculator_1.estimateNativeValueForSwap)(ctx, universalCoreAddress, gasToken, gasFee, ueaBalance);
288
+ if (estimated > nativeValueForGas) {
289
+ (0, context_1.printLog)(ctx, `executeUoaToCea — pool-price estimate: ${estimated.toString()} ` +
290
+ `(was ${nativeValueForGas.toString()}), UEA balance: ${ueaBalance.toString()}`);
291
+ nativeValueForGas = estimated;
292
+ }
293
+ }
294
+ // Balance-aware cap: avoid draining the entire UEA balance for gas.
295
+ // The contract's swapAndBurnGas does exactOutputSingle and refunds excess PC,
296
+ // so overshooting within balance is safe.
282
297
  const EVM_NATIVE_VALUE_TARGET = BigInt(200e18); // 200 UPC
283
298
  const EVM_GAS_RESERVE = BigInt(3e18); // 3 UPC for tx overhead
284
- // Reuse ueaBalance fetched earlier (line 383) — no tx sent between, balance is stable
285
299
  const currentBalance = ueaBalance;
286
- // Balance-aware adjustment — same logic whether UEA is deployed or not.
287
- // The old !isUEADeployed branch blindly used 200 UPC assuming fee-locking
288
- // would deposit enough, but the actual deposit depends on origin-chain ETH
289
- // locked — not a guaranteed 200 UPC. This caused executeUniversalTx to
290
- // revert when UEA balance < 200 UPC. The contract's swapAndBurnGas does
291
- // exactOutputSingle and refunds excess PC, so overshooting within balance
292
- // is safe.
293
300
  let adjustedValue;
294
301
  if (currentBalance > EVM_NATIVE_VALUE_TARGET + EVM_GAS_RESERVE) {
295
- // Enough balance: use 200 UPC target
296
- adjustedValue = EVM_NATIVE_VALUE_TARGET;
302
+ // Enough balance: cap at 200 UPC (pool estimate may be lower)
303
+ adjustedValue = nativeValueForGas < EVM_NATIVE_VALUE_TARGET
304
+ ? nativeValueForGas
305
+ : EVM_NATIVE_VALUE_TARGET;
297
306
  }
298
307
  else if (currentBalance > EVM_GAS_RESERVE) {
299
308
  // Low balance: use what's available minus reserve
300
- adjustedValue = currentBalance - EVM_GAS_RESERVE;
309
+ const available = currentBalance - EVM_GAS_RESERVE;
310
+ adjustedValue = nativeValueForGas < available ? nativeValueForGas : available;
301
311
  }
302
312
  else {
303
- // Very low balance: use original query value as-is
313
+ // Very low/zero balance (fresh wallet). The pool-price estimate (now in
314
+ // nativeValueForGas) is accurate. Fee-locking will deposit enough UPC
315
+ // because requiredFunds includes this value, and lockFee floors at $1.
304
316
  adjustedValue = nativeValueForGas;
305
317
  }
306
318
  if (adjustedValue !== nativeValueForGas) {