@pafi-dev/core 0.7.5 → 0.7.6

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.
Files changed (2) hide show
  1. package/README.md +84 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -49,6 +49,10 @@ in sibling packages:
49
49
  > **0.6.1 (2026-04-27):** added `quoteOperatorFeeUsdt` so FE can
50
50
  > compute USDT-denominated gas fee without round-tripping the issuer
51
51
  > backend (`/gas-fee` is now optional).
52
+ >
53
+ > **0.7.5 (2026-04-28):** added `delegateDirect()` — FE one-shot EIP-7702
54
+ > delegation that user pays gas for. Bypasses the AA + sponsor-relayer
55
+ > stack entirely. See [section below](#delegatedirect--fe-one-shot-delegation-no-aa--no-sponsor).
52
56
 
53
57
  ---
54
58
 
@@ -65,6 +69,7 @@ in sibling packages:
65
69
  | `encodeBatchExecute`, `decodeBatchExecuteCalls` | BatchExecutor (Coinbase SW v2) calldata |
66
70
  | `buildDelegationUserOp`, `computeAuthorizationHash`, `parseEip7702DelegatedAddress` | EIP-7702 helpers |
67
71
  | `splitAuthorizationSig`, `buildEip7702Authorization` | Split user's authSig + assemble bundler tuple |
72
+ | `delegateDirect` | One-shot FE-direct EIP-7702 delegation (user pays gas, no AA) |
68
73
  | `buildPerpDepositViaRelay`, `buildPerpDepositWithGasDeduction`, `ORDERLY_RELAY_ABI`, `ORDERLY_VAULT_ABI`, `BROKER_HASHES`, `TOKEN_HASHES`, `computeAccountId` | Orderly perp deposit calldata + types |
69
74
  | `quoteOperatorFeePt`, `quoteOperatorFeeUsdt` | Off-issuer fee quoter (Chainlink + V4 subgraph) |
70
75
  | `fetchPafiPools`, `PAFI_SUBGRAPH_URL` | Pool discovery via PAFI subgraph |
@@ -186,6 +191,85 @@ const authorization = buildEip7702Authorization({
186
191
 
187
192
  ---
188
193
 
194
+ ## `delegateDirect` — FE one-shot delegation, no AA / no sponsor
195
+
196
+ For the **FE-direct** path where the user pays gas in ETH and you don't
197
+ want a dependency on `permissionless` / Pimlico bundlers / PAFI
198
+ sponsor-relayer:
199
+
200
+ ```ts
201
+ import { useSign7702Authorization, useWallets } from "@privy-io/react-auth";
202
+ import { delegateDirect } from "@pafi-dev/core";
203
+ import { createWalletClient, custom, createPublicClient, http } from "viem";
204
+ import { base } from "viem/chains";
205
+
206
+ const publicClient = createPublicClient({ chain: base, transport: http() });
207
+
208
+ function DelegateButton() {
209
+ const { wallets } = useWallets();
210
+ const { signAuthorization } = useSign7702Authorization();
211
+
212
+ // Privy ALWAYS signs EIP-7702 with the embedded wallet — pick that
213
+ // one as the smart-account owner regardless of how user logged in.
214
+ const wallet = wallets.find((w) => w.walletClientType === "privy");
215
+
216
+ async function handleClick() {
217
+ if (!wallet) return;
218
+ const provider = await wallet.getEthereumProvider();
219
+ const walletClient = createWalletClient({
220
+ account: wallet.address as `0x${string}`,
221
+ chain: base,
222
+ transport: custom(provider),
223
+ });
224
+
225
+ const result = await delegateDirect({
226
+ userAddress: wallet.address as `0x${string}`,
227
+ chainId: 8453,
228
+ publicClient,
229
+ walletClient,
230
+ signAuthorization,
231
+ // optional: skipIfAlreadyDelegated (default true), waitForReceipt (default true)
232
+ });
233
+
234
+ if (result.status === "already-delegated") {
235
+ console.log("Already delegated to", result.delegatedTo);
236
+ } else {
237
+ console.log("Delegated! tx:", result.txHash);
238
+ // result.receipt — full TransactionReceipt when waitForReceipt=true
239
+ }
240
+ }
241
+
242
+ return <button onClick={handleClick}>Delegate</button>;
243
+ }
244
+ ```
245
+
246
+ **What happens internally:**
247
+
248
+ 1. `getCode(userAddress)` → if already delegated to expected impl, return early.
249
+ 2. `getTransactionCount(userAddress, 'pending')` → tx nonce.
250
+ 3. `signAuthorization({ contractAddress, chainId, nonce })` — Privy hook signs with embedded wallet (raw `secp256k1_sign`, no EIP-191 prefix).
251
+ 4. `walletClient.sendTransaction({ to: userAddress, data: '0x', authorizationList: [auth] })` — viem encodes a type-4 EIP-7702 transaction.
252
+ 5. `waitForTransactionReceipt(txHash)` (optional).
253
+
254
+ **Requirements:**
255
+
256
+ - Privy embedded wallet (external wallets like MetaMask **cannot**
257
+ sign EIP-7702 — only Privy's embedded wallet exposes raw
258
+ `secp256k1_sign`).
259
+ - A few cents of ETH on Base for gas (~$0.01–0.10).
260
+
261
+ **vs. AA path:** `delegateDirect` produces 1 native L1 tx instead of an
262
+ ERC-4337 UserOp. Cheaper, simpler, no bundler / paymaster involvement —
263
+ but the user pays gas. Use the AA path (via `permissionless` +
264
+ sponsor-relayer) when you want gas-free UX.
265
+
266
+ **vs. mobile gg56 flow:** mobile delegate flow goes through gg56's
267
+ `/delegate/{prepare,submit}` + sponsor-relayer for the gas sponsorship.
268
+ `delegateDirect` is the FE-only counterpart that bypasses that
269
+ infrastructure entirely.
270
+
271
+ ---
272
+
189
273
  ## Operator fee quoter
190
274
 
191
275
  Two helpers for FE direct-mode usage (no backend round-trip):
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pafi-dev/core",
3
- "version": "0.7.5",
3
+ "version": "0.7.6",
4
4
  "description": "EIP-712 signing, contract interaction, and Relay calldata for the PAFI point token system",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",