@pafi-dev/issuer 0.6.0 → 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
@@ -1894,14 +1894,19 @@ type DecodedCall = ReturnType<typeof decodeBatchExecuteCalls>[number];
1894
1894
  * quotes the Relay's USDC fee (covers LayerZero msg.value out of the
1895
1895
  * Relay's ETH reserve), then builds two UserOps:
1896
1896
  *
1897
- * - **sponsored** — PT.transfer(fee, PAFI) + USDC.approve(relay,
1898
- * total) + Relay.deposit(req). User reimburses gas in PT.
1897
+ * - **sponsored** — USDC.transfer(fee, PAFI) + USDC.approve(relay,
1898
+ * total) + Relay.deposit(req). User reimburses gas in USDC
1899
+ * (input-token rule — user holds USDC at start of batch).
1899
1900
  * - **fallback** — USDC.approve + Relay.deposit only. User pays
1900
1901
  * ERC-4337 gas in ETH. Built only when `feeAmount > 0`.
1901
1902
  *
1902
1903
  * `maxFee` is set to `quote × 1.5` — slippage cap on the Relay's
1903
1904
  * USD-pricing during the inclusion window. If the actual fee at
1904
1905
  * execution exceeds maxFee the Relay reverts (`FeeExceedsMax`).
1906
+ *
1907
+ * v0.7 — Switched gas fee from PT (output-side, mixed token UX) to
1908
+ * USDC (input-side, single token UX). User now only needs USDC to
1909
+ * complete the deposit, no separate PT balance required.
1905
1910
  */
1906
1911
  type PerpDepositErrorCode = "PERP_DEPOSIT_UNAVAILABLE" | "BROKER_NOT_WHITELISTED" | "RELAY_FEE_EXCEEDS_AMOUNT" | "FEE_EXCEEDS_AMOUNT" | "INVALID_AMOUNT";
1907
1912
  declare class PerpDepositError extends PafiSdkError {
@@ -1912,16 +1917,20 @@ declare class PerpDepositError extends PafiSdkError {
1912
1917
  }
1913
1918
  interface PerpDepositHandlerConfig {
1914
1919
  provider: PublicClient;
1915
- /** Optional — when wired, used to estimate the PT gas-reimbursement fee. */
1916
- feeService?: FeeManager;
1917
- /** PointToken address used for the sponsored PT.transfer. */
1918
- pointTokenAddress: Address;
1919
1920
  /**
1920
1921
  * Slippage premium applied on top of the Relay quote when computing
1921
1922
  * `maxFee`. Default 50% (factor 150). The Relay reverts if actual fee
1922
1923
  * exceeds `maxFee` so a generous cap reduces re-quote churn.
1923
1924
  */
1924
1925
  maxFeePremiumBps?: number;
1926
+ /**
1927
+ * Gas units used by `quoteOperatorFeeUsdt` to size the USDC gas
1928
+ * reimbursement. Default 500_000 (covers approve + Relay.deposit
1929
+ * + LayerZero call). Pass a tighter Pimlico estimate if available.
1930
+ */
1931
+ gasUnits?: bigint;
1932
+ /** Premium bps for `quoteOperatorFeeUsdt`. Default 12_000 (1.2×). */
1933
+ gasPremiumBps?: number;
1925
1934
  }
1926
1935
  interface PerpDepositRequest {
1927
1936
  userAddress: Address;
package/dist/index.d.ts CHANGED
@@ -1894,14 +1894,19 @@ type DecodedCall = ReturnType<typeof decodeBatchExecuteCalls>[number];
1894
1894
  * quotes the Relay's USDC fee (covers LayerZero msg.value out of the
1895
1895
  * Relay's ETH reserve), then builds two UserOps:
1896
1896
  *
1897
- * - **sponsored** — PT.transfer(fee, PAFI) + USDC.approve(relay,
1898
- * total) + Relay.deposit(req). User reimburses gas in PT.
1897
+ * - **sponsored** — USDC.transfer(fee, PAFI) + USDC.approve(relay,
1898
+ * total) + Relay.deposit(req). User reimburses gas in USDC
1899
+ * (input-token rule — user holds USDC at start of batch).
1899
1900
  * - **fallback** — USDC.approve + Relay.deposit only. User pays
1900
1901
  * ERC-4337 gas in ETH. Built only when `feeAmount > 0`.
1901
1902
  *
1902
1903
  * `maxFee` is set to `quote × 1.5` — slippage cap on the Relay's
1903
1904
  * USD-pricing during the inclusion window. If the actual fee at
1904
1905
  * execution exceeds maxFee the Relay reverts (`FeeExceedsMax`).
1906
+ *
1907
+ * v0.7 — Switched gas fee from PT (output-side, mixed token UX) to
1908
+ * USDC (input-side, single token UX). User now only needs USDC to
1909
+ * complete the deposit, no separate PT balance required.
1905
1910
  */
1906
1911
  type PerpDepositErrorCode = "PERP_DEPOSIT_UNAVAILABLE" | "BROKER_NOT_WHITELISTED" | "RELAY_FEE_EXCEEDS_AMOUNT" | "FEE_EXCEEDS_AMOUNT" | "INVALID_AMOUNT";
1907
1912
  declare class PerpDepositError extends PafiSdkError {
@@ -1912,16 +1917,20 @@ declare class PerpDepositError extends PafiSdkError {
1912
1917
  }
1913
1918
  interface PerpDepositHandlerConfig {
1914
1919
  provider: PublicClient;
1915
- /** Optional — when wired, used to estimate the PT gas-reimbursement fee. */
1916
- feeService?: FeeManager;
1917
- /** PointToken address used for the sponsored PT.transfer. */
1918
- pointTokenAddress: Address;
1919
1920
  /**
1920
1921
  * Slippage premium applied on top of the Relay quote when computing
1921
1922
  * `maxFee`. Default 50% (factor 150). The Relay reverts if actual fee
1922
1923
  * exceeds `maxFee` so a generous cap reduces re-quote churn.
1923
1924
  */
1924
1925
  maxFeePremiumBps?: number;
1926
+ /**
1927
+ * Gas units used by `quoteOperatorFeeUsdt` to size the USDC gas
1928
+ * reimbursement. Default 500_000 (covers approve + Relay.deposit
1929
+ * + LayerZero call). Pass a tighter Pimlico estimate if available.
1930
+ */
1931
+ gasUnits?: bigint;
1932
+ /** Premium bps for `quoteOperatorFeeUsdt`. Default 12_000 (1.2×). */
1933
+ gasPremiumBps?: number;
1925
1934
  }
1926
1935
  interface PerpDepositRequest {
1927
1936
  userAddress: Address;
package/dist/index.js CHANGED
@@ -2040,7 +2040,8 @@ import {
2040
2040
  buildPerpDepositViaRelay,
2041
2041
  computeAccountId,
2042
2042
  decodeBatchExecuteCalls as decodeBatchExecuteCalls2,
2043
- getContractAddresses as getContractAddresses4
2043
+ getContractAddresses as getContractAddresses4,
2044
+ quoteOperatorFeeUsdt
2044
2045
  } from "@pafi-dev/core";
2045
2046
  var PerpDepositError = class extends PafiSdkError {
2046
2047
  httpStatus = "unprocessable";
@@ -2103,14 +2104,19 @@ var PerpDepositHandler = class {
2103
2104
  totalAmount: request.amount,
2104
2105
  maxFee: 0n
2105
2106
  };
2106
- const [relayTokenFee, ptGasFee] = await Promise.all([
2107
+ const [relayTokenFee, usdcGasFee] = await Promise.all([
2107
2108
  this.cfg.provider.readContract({
2108
2109
  address: relayAddress,
2109
2110
  abi: ORDERLY_RELAY_ABI,
2110
2111
  functionName: "quoteTokenFee",
2111
2112
  args: [requestForQuote]
2112
2113
  }),
2113
- this.cfg.feeService ? this.cfg.feeService.estimateGasFee() : Promise.resolve(0n)
2114
+ quoteOperatorFeeUsdt({
2115
+ provider: this.cfg.provider,
2116
+ chainId: request.chainId,
2117
+ gasUnits: this.cfg.gasUnits,
2118
+ premiumBps: this.cfg.gasPremiumBps
2119
+ })
2114
2120
  ]);
2115
2121
  if (relayTokenFee >= request.amount) {
2116
2122
  throw new PerpDepositError(
@@ -2118,6 +2124,12 @@ var PerpDepositHandler = class {
2118
2124
  `Relay quoted fee ${relayTokenFee} >= deposit amount ${request.amount}`
2119
2125
  );
2120
2126
  }
2127
+ if (usdcGasFee > 0n && usdcGasFee >= request.amount) {
2128
+ throw new PerpDepositError(
2129
+ "FEE_EXCEEDS_AMOUNT",
2130
+ `USDC gas fee ${usdcGasFee} >= deposit amount ${request.amount}`
2131
+ );
2132
+ }
2121
2133
  const maxFee = relayTokenFee * BigInt(1e4 + this.cfg.maxFeePremiumBps) / 10000n;
2122
2134
  const depositReq = {
2123
2135
  token: usdcAddress,
@@ -2131,11 +2143,10 @@ var PerpDepositHandler = class {
2131
2143
  aaNonce: request.aaNonce,
2132
2144
  relayAddress,
2133
2145
  request: depositReq,
2134
- pointTokenAddress: this.cfg.pointTokenAddress,
2135
- gasFeePt: ptGasFee,
2136
- gasFeePtRecipient: pafiFeeRecipient
2146
+ gasFeeUsdc: usdcGasFee,
2147
+ gasFeeUsdcRecipient: pafiFeeRecipient
2137
2148
  });
2138
- const fallbackOp = ptGasFee > 0n ? buildPerpDepositViaRelay({
2149
+ const fallbackOp = usdcGasFee > 0n ? buildPerpDepositViaRelay({
2139
2150
  userAddress: request.userAddress,
2140
2151
  aaNonce: request.aaNonce,
2141
2152
  relayAddress,
@@ -2144,7 +2155,7 @@ var PerpDepositHandler = class {
2144
2155
  return {
2145
2156
  userOp: sponsoredOp,
2146
2157
  fallback: fallbackOp,
2147
- feeAmount: ptGasFee,
2158
+ feeAmount: usdcGasFee,
2148
2159
  relayTokenFee,
2149
2160
  maxFee,
2150
2161
  netDeposit: request.amount - relayTokenFee,