@pafi-dev/core 0.6.2 → 0.7.0

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/dist/index.d.cts CHANGED
@@ -505,14 +505,20 @@ interface BuildPerpDepositViaRelayParams {
505
505
  /** Deposit request (token, receiver, brokerHash, totalAmount, maxFee). */
506
506
  request: OrderlyRelayDepositRequest;
507
507
  /**
508
- * Optional PT gas-fee transfer prepended to the batch. Set both
509
- * `gasFeePtRecipient` and `gasFeePt` together for sponsored flows
510
- * (PAFI gas reimbursement). Pass `0n` / `undefined` for the fallback
511
- * path where the user pays ERC-4337 gas in ETH directly.
508
+ * Optional USDC (input-token) gas-fee transfer prepended to the batch.
509
+ * The user holds USDC at the start of the batch, so the fee comes out
510
+ * of the same input token no second-token requirement. Set both
511
+ * `gasFeeUsdcRecipient` and `gasFeeUsdc` together for sponsored
512
+ * flows (PAFI gas reimbursement). Pass `0n` / `undefined` for the
513
+ * fallback path where the user pays ERC-4337 gas in ETH directly.
514
+ *
515
+ * v0.7 — input-token fee position rule: user holds USDC BEFORE
516
+ * deposit (token-availability), so charge there. Replaces the old
517
+ * `gasFeePt` / `gasFeePtRecipient` / `pointTokenAddress` triple from
518
+ * v0.6.
512
519
  */
513
- pointTokenAddress?: Address;
514
- gasFeePt?: bigint;
515
- gasFeePtRecipient?: Address;
520
+ gasFeeUsdc?: bigint;
521
+ gasFeeUsdcRecipient?: Address;
516
522
  gasLimits?: {
517
523
  callGasLimit?: bigint;
518
524
  verificationGasLimit?: bigint;
@@ -522,10 +528,14 @@ interface BuildPerpDepositViaRelayParams {
522
528
  /**
523
529
  * Build a UserOp for Orderly perp deposit via the PAFI Relay.
524
530
  *
525
- * Sponsored ops: `[PT.transfer(feeRecipient, gasFeePt), USDC.approve(relay, total), Relay.deposit(req)]`
526
- * Fallback ops: `[ USDC.approve(relay, total), Relay.deposit(req)]`
531
+ * Sponsored ops: `[USDC.transfer(feeRecipient, gasFeeUsdc), USDC.approve(relay, total), Relay.deposit(req)]`
532
+ * Fallback ops: `[ USDC.approve(relay, total), Relay.deposit(req)]`
527
533
  *
528
534
  * No `msg.value` — the Relay covers LayerZero out of its own ETH reserve.
535
+ *
536
+ * Fee position rule: user holds USDC at start of batch → fee transfer
537
+ * runs FIRST in the same token. User must hold `totalAmount + gasFeeUsdc`
538
+ * USDC; net deposit to Orderly is `totalAmount - relayTokenFee`.
529
539
  */
530
540
  declare function buildPerpDepositViaRelay(params: BuildPerpDepositViaRelayParams): PartialUserOperation;
531
541
 
package/dist/index.d.ts CHANGED
@@ -505,14 +505,20 @@ interface BuildPerpDepositViaRelayParams {
505
505
  /** Deposit request (token, receiver, brokerHash, totalAmount, maxFee). */
506
506
  request: OrderlyRelayDepositRequest;
507
507
  /**
508
- * Optional PT gas-fee transfer prepended to the batch. Set both
509
- * `gasFeePtRecipient` and `gasFeePt` together for sponsored flows
510
- * (PAFI gas reimbursement). Pass `0n` / `undefined` for the fallback
511
- * path where the user pays ERC-4337 gas in ETH directly.
508
+ * Optional USDC (input-token) gas-fee transfer prepended to the batch.
509
+ * The user holds USDC at the start of the batch, so the fee comes out
510
+ * of the same input token no second-token requirement. Set both
511
+ * `gasFeeUsdcRecipient` and `gasFeeUsdc` together for sponsored
512
+ * flows (PAFI gas reimbursement). Pass `0n` / `undefined` for the
513
+ * fallback path where the user pays ERC-4337 gas in ETH directly.
514
+ *
515
+ * v0.7 — input-token fee position rule: user holds USDC BEFORE
516
+ * deposit (token-availability), so charge there. Replaces the old
517
+ * `gasFeePt` / `gasFeePtRecipient` / `pointTokenAddress` triple from
518
+ * v0.6.
512
519
  */
513
- pointTokenAddress?: Address;
514
- gasFeePt?: bigint;
515
- gasFeePtRecipient?: Address;
520
+ gasFeeUsdc?: bigint;
521
+ gasFeeUsdcRecipient?: Address;
516
522
  gasLimits?: {
517
523
  callGasLimit?: bigint;
518
524
  verificationGasLimit?: bigint;
@@ -522,10 +528,14 @@ interface BuildPerpDepositViaRelayParams {
522
528
  /**
523
529
  * Build a UserOp for Orderly perp deposit via the PAFI Relay.
524
530
  *
525
- * Sponsored ops: `[PT.transfer(feeRecipient, gasFeePt), USDC.approve(relay, total), Relay.deposit(req)]`
526
- * Fallback ops: `[ USDC.approve(relay, total), Relay.deposit(req)]`
531
+ * Sponsored ops: `[USDC.transfer(feeRecipient, gasFeeUsdc), USDC.approve(relay, total), Relay.deposit(req)]`
532
+ * Fallback ops: `[ USDC.approve(relay, total), Relay.deposit(req)]`
527
533
  *
528
534
  * No `msg.value` — the Relay covers LayerZero out of its own ETH reserve.
535
+ *
536
+ * Fee position rule: user holds USDC at start of batch → fee transfer
537
+ * runs FIRST in the same token. User must hold `totalAmount + gasFeeUsdc`
538
+ * USDC; net deposit to Orderly is `totalAmount - relayTokenFee`.
529
539
  */
530
540
  declare function buildPerpDepositViaRelay(params: BuildPerpDepositViaRelayParams): PartialUserOperation;
531
541
 
package/dist/index.js CHANGED
@@ -344,7 +344,7 @@ function buildPerpDepositWithGasDeduction(params) {
344
344
  }
345
345
 
346
346
  // src/perp/buildPerpDepositViaRelay.ts
347
- import { encodeFunctionData as encodeFunctionData4, erc20Abi as erc20Abi3 } from "viem";
347
+ import { encodeFunctionData as encodeFunctionData4 } from "viem";
348
348
  var ORDERLY_RELAY_ABI = [
349
349
  {
350
350
  type: "function",
@@ -396,26 +396,19 @@ function buildPerpDepositViaRelay(params) {
396
396
  throw new Error("buildPerpDepositViaRelay: relayAddress required");
397
397
  }
398
398
  const operations = [];
399
- if (params.gasFeePt && params.gasFeePt > 0n) {
400
- if (!params.pointTokenAddress) {
399
+ if (params.gasFeeUsdc && params.gasFeeUsdc > 0n) {
400
+ if (!params.gasFeeUsdcRecipient) {
401
401
  throw new Error(
402
- "buildPerpDepositViaRelay: pointTokenAddress required when gasFeePt > 0"
402
+ "buildPerpDepositViaRelay: gasFeeUsdcRecipient required when gasFeeUsdc > 0"
403
403
  );
404
404
  }
405
- if (!params.gasFeePtRecipient) {
406
- throw new Error(
407
- "buildPerpDepositViaRelay: gasFeePtRecipient required when gasFeePt > 0"
408
- );
409
- }
410
- operations.push({
411
- target: params.pointTokenAddress,
412
- value: 0n,
413
- data: encodeFunctionData4({
414
- abi: erc20Abi3,
415
- functionName: "transfer",
416
- args: [params.gasFeePtRecipient, params.gasFeePt]
417
- })
418
- });
405
+ operations.push(
406
+ erc20TransferOp(
407
+ params.request.token,
408
+ params.gasFeeUsdcRecipient,
409
+ params.gasFeeUsdc
410
+ )
411
+ );
419
412
  }
420
413
  operations.push(
421
414
  erc20ApproveOp(