@pafi-dev/trading 0.1.2 → 0.1.4

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 +87 -1
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -15,7 +15,12 @@ client-side (React, React Native).
15
15
 
16
16
  - Node.js >= 18 (server) or any modern bundler (client)
17
17
  - TypeScript >= 5.0
18
- - `viem` ^2.0.0 and `@pafi-dev/core` ^0.5.0 (peer dependencies)
18
+ - `viem` ^2.0.0 and `@pafi-dev/core` ^0.5.17 (peer dependencies)
19
+
20
+ > **Latest:** `0.1.3` — bumps the `@pafi-dev/core` peer to `0.5.17` for
21
+ > the v0.8 EIP-712 userOpHash + `buildUserOpTypedData()` helpers required
22
+ > by the EIP-7702 swap path. Also adds a frontend "quote review"
23
+ > example. See [Changelog](#changelog).
19
24
 
20
25
  ---
21
26
 
@@ -65,6 +70,64 @@ const quote = await trading.handleQuote({
65
70
  Returns `quoteError` instead of throwing when no pool/path is found, so the caller can
66
71
  show a soft "unavailable" UI state without 500-ing.
67
72
 
73
+ #### Frontend "quote review" pattern
74
+
75
+ Quotes are pure on-chain reads (Uniswap V4 Quoter via Base RPC) — **no
76
+ auth, no issuer-side state, nothing to proxy through the issuer
77
+ backend.** Call `handleQuote` directly from the browser / React Native.
78
+
79
+ ```tsx
80
+ import { TradingHandlers, fetchPafiPools } from "@pafi-dev/trading";
81
+ import { createPublicClient, http, formatUnits } from "viem";
82
+ import { base } from "viem/chains";
83
+
84
+ const trading = new TradingHandlers({
85
+ provider: createPublicClient({ chain: base, transport: http(RPC_URL) }),
86
+ chainId: 8453,
87
+ });
88
+
89
+ useEffect(() => {
90
+ if (amount <= 0n) return setQuote(null);
91
+ const t = setTimeout(async () => {
92
+ const pools = await fetchPafiPools(8453, POINT_TOKEN);
93
+ const result = await trading.handleQuote({
94
+ chainId: 8453,
95
+ pointTokenAddress: POINT_TOKEN,
96
+ amount,
97
+ pools,
98
+ });
99
+ setQuote(result);
100
+ }, 400);
101
+ return () => clearTimeout(t);
102
+ }, [amount]);
103
+
104
+ // Render:
105
+ // In: formatUnits(amount, 18) PT
106
+ // You receive: formatUnits(quote.estimatedUsdtOut, 6) USDT
107
+ // Rate: estimatedUsdtOut · 1e18 / amount / 1e6 USDT per 1 PT
108
+ // On `quote.quoteError === "QUOTE_UNAVAILABLE"` → hide the Swap CTA.
109
+ ```
110
+
111
+ Why client-direct (no `GET /quote` HTTP hop):
112
+
113
+ - The quoter is stateless and reads from the public RPC — there's no
114
+ secret to hide and nothing to validate against an issuer's database.
115
+ - One fewer round-trip on every keystroke (debounce hits the Quoter
116
+ directly, ~150 ms vs. ~400 ms via a backend proxy).
117
+ - The quote stays internally consistent with the swap path that
118
+ `handleSwap` will pick — both use the same `findBestQuote()` call
119
+ under the hood with the same `pools` array, so what the user sees in
120
+ the review card is what they get on submit.
121
+
122
+ > **Operator fee in USDT** is **NOT** part of the quote — it's an
123
+ > issuer-policy concern decided at swap-build time. If you want a
124
+ > "net out after fee" preview, fetch the issuer's gas-fee endpoint
125
+ > separately and subtract on the client.
126
+
127
+ Reference implementation lives in
128
+ [`privy-pimlico-eip7702-example/app/components/WalletPanel.tsx`](https://github.com/pacific-finance/pafi-backend/blob/main/privy-pimlico-eip7702-example/app/components/WalletPanel.tsx)
129
+ (search for `Quote review`).
130
+
68
131
  ---
69
132
 
70
133
  ### `handleSwap` — POST /swap
@@ -234,6 +297,29 @@ It does not depend on `@pafi-dev/issuer`.
234
297
 
235
298
  ---
236
299
 
300
+ ## Changelog
301
+
302
+ ### 0.1.3
303
+
304
+ - Peer dependency `@pafi-dev/core` bumped to `0.5.17` so the swap path
305
+ picks up `buildUserOpTypedData()` + the v0.8 EIP-712 `computeUserOpHash`.
306
+ Required for the EIP-7702 mobile swap flow on Pimlico's
307
+ `Simple7702Account` — the previous v0.7 hash format and EIP-191
308
+ signing path both reverted with `AA24 signature error`. See
309
+ [`@pafi-dev/core` changelog 0.5.16](../core/README.md#0516).
310
+ - README adds a **frontend "quote review" pattern** — debounced
311
+ `/quote` polling so the user sees `X PT → ~Y USDT` (after operator
312
+ gas fee) before submitting the swap UserOp. Reference implementation
313
+ in `privy-pimlico-eip7702-example/app/components/WalletPanel.tsx`.
314
+
315
+ ### 0.1.2
316
+
317
+ - Initial public release. `handleQuote`, `handleSwap`,
318
+ `handlePerpDeposit` stateless handlers + `fetchPafiPools` subgraph
319
+ helper.
320
+
321
+ ---
322
+
237
323
  ## License
238
324
 
239
325
  Apache-2.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pafi-dev/trading",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Stateless on-chain trading handlers for PAFI — swap, quote, perp deposit",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -22,7 +22,7 @@
22
22
  "dist"
23
23
  ],
24
24
  "dependencies": {
25
- "@pafi-dev/core": "0.5.2"
25
+ "@pafi-dev/core": "0.5.17"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "viem": "^2.0.0"