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

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.8",
3
+ "version": "5.1.4-alpha.9",
4
4
  "homepage": "https://push.org",
5
5
  "keywords": [
6
6
  "pushchain",
@@ -283,19 +283,22 @@ function executeUoaToCea(ctx, params, executeFn) {
283
283
  // pool's slot0, computes the true cost, and adds a 2x buffer.
284
284
  // This matches the SVM path (executeUoaToCeaSvm) which already uses this.
285
285
  // Excess msg.value is refunded by the contract's swapAndBurnGas.
286
+ const EVM_NATIVE_VALUE_TARGET = BigInt(200e18); // 200 UPC
287
+ const EVM_GAS_RESERVE = BigInt(3e18); // 3 UPC for tx overhead
286
288
  if (universalCoreAddress && gasFee > BigInt(0)) {
287
- const estimated = yield (0, gas_calculator_1.estimateNativeValueForSwap)(ctx, universalCoreAddress, gasToken, gasFee, ueaBalance);
289
+ // When UEA balance is 0, pass EVM_NATIVE_VALUE_TARGET as the balance hint
290
+ // so the pool estimate isn't capped/fallback'd to zero.
291
+ const balanceHint = ueaBalance > BigInt(0) ? ueaBalance : EVM_NATIVE_VALUE_TARGET;
292
+ const estimated = yield (0, gas_calculator_1.estimateNativeValueForSwap)(ctx, universalCoreAddress, gasToken, gasFee, balanceHint);
288
293
  if (estimated > nativeValueForGas) {
289
294
  (0, context_1.printLog)(ctx, `executeUoaToCea — pool-price estimate: ${estimated.toString()} ` +
290
295
  `(was ${nativeValueForGas.toString()}), UEA balance: ${ueaBalance.toString()}`);
291
296
  nativeValueForGas = estimated;
292
297
  }
293
298
  }
294
- // Balance-aware cap: avoid draining the entire UEA balance for gas.
299
+ // Balance-aware adjustment: avoid draining the entire UEA balance for gas.
295
300
  // The contract's swapAndBurnGas does exactOutputSingle and refunds excess PC,
296
301
  // so overshooting within balance is safe.
297
- const EVM_NATIVE_VALUE_TARGET = BigInt(200e18); // 200 UPC
298
- const EVM_GAS_RESERVE = BigInt(3e18); // 3 UPC for tx overhead
299
302
  const currentBalance = ueaBalance;
300
303
  let adjustedValue;
301
304
  if (currentBalance > EVM_NATIVE_VALUE_TARGET + EVM_GAS_RESERVE) {
@@ -309,10 +312,21 @@ function executeUoaToCea(ctx, params, executeFn) {
309
312
  const available = currentBalance - EVM_GAS_RESERVE;
310
313
  adjustedValue = nativeValueForGas < available ? nativeValueForGas : available;
311
314
  }
315
+ else if (!isUEADeployed) {
316
+ // Fresh wallet: UEA not deployed, fee-locking WILL run and deposit funds.
317
+ // Use EVM_NATIVE_VALUE_TARGET (200 UPC) — fee-locking auto-covers this
318
+ // because requiredFunds includes nativeValueForGas, and lockFee converts
319
+ // the UPC amount to USD and deposits the equivalent ETH.
320
+ // The contract's swapAndBurnGas refunds any excess.
321
+ // If pool estimate produced a usable value, prefer it (capped at 200 UPC).
322
+ adjustedValue = nativeValueForGas > EVM_NATIVE_VALUE_TARGET
323
+ ? EVM_NATIVE_VALUE_TARGET
324
+ : nativeValueForGas > BigInt(0) ? nativeValueForGas : EVM_NATIVE_VALUE_TARGET;
325
+ (0, context_1.printLog)(ctx, `executeUoaToCea — fresh wallet (UEA not deployed): using ${adjustedValue.toString()} for nativeValueForGas`);
326
+ }
312
327
  else {
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.
328
+ // Deployed UEA with near-zero balance: best-effort with pool/1M estimate.
329
+ // User may need to add funds to UEA manually.
316
330
  adjustedValue = nativeValueForGas;
317
331
  }
318
332
  if (adjustedValue !== nativeValueForGas) {