@pafi-dev/trading 0.1.2 → 0.1.3

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 +63 -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,40 @@ 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
+ The mobile / web client should refresh `/quote` whenever the user types a
76
+ new amount, so the swap CTA always shows the exact USDT they will
77
+ receive (after the operator gas fee in USDT). Example: poll
78
+ `GET /quote?chainId&pointToken&amount` on a 400 ms debounce after each
79
+ keystroke and render a card with `pointAmount → estimatedUsdtOut −
80
+ gasFeeUsdt = netUsdtOut` plus the `exchangeRate`.
81
+
82
+ ```tsx
83
+ const [quote, setQuote] = useState<QuoteResponseDto | null>(null);
84
+
85
+ useEffect(() => {
86
+ if (!token || amount <= 0n) return setQuote(null);
87
+ const t = setTimeout(async () => {
88
+ const url = `${API}/quote?chainId=8453&pointToken=${POINT_TOKEN}&amount=${amount}`;
89
+ const res = await fetch(url, { headers: { Authorization: `Bearer ${token}` } });
90
+ setQuote(await res.json());
91
+ }, 400);
92
+ return () => clearTimeout(t);
93
+ }, [amount, token]);
94
+
95
+ // quote.estimatedUsdtOut → "you will receive ~Y USDT"
96
+ // quote.gasFeeUsdt → "operator gas fee deducted from output"
97
+ // quote.netUsdtOut → "actually credited to your wallet"
98
+ // quote.exchangeRate → "1 PT ≈ ${rate} USDT"
99
+ // quote.quoteError → render warning, hide the Swap CTA
100
+ ```
101
+
102
+ A working implementation lives in
103
+ [`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)
104
+ (search for `Quote review`). It reuses the same `/quote` endpoint the
105
+ issuer backend exposes — no extra SDK call needed on the client.
106
+
68
107
  ---
69
108
 
70
109
  ### `handleSwap` — POST /swap
@@ -234,6 +273,29 @@ It does not depend on `@pafi-dev/issuer`.
234
273
 
235
274
  ---
236
275
 
276
+ ## Changelog
277
+
278
+ ### 0.1.3
279
+
280
+ - Peer dependency `@pafi-dev/core` bumped to `0.5.17` so the swap path
281
+ picks up `buildUserOpTypedData()` + the v0.8 EIP-712 `computeUserOpHash`.
282
+ Required for the EIP-7702 mobile swap flow on Pimlico's
283
+ `Simple7702Account` — the previous v0.7 hash format and EIP-191
284
+ signing path both reverted with `AA24 signature error`. See
285
+ [`@pafi-dev/core` changelog 0.5.16](../core/README.md#0516).
286
+ - README adds a **frontend "quote review" pattern** — debounced
287
+ `/quote` polling so the user sees `X PT → ~Y USDT` (after operator
288
+ gas fee) before submitting the swap UserOp. Reference implementation
289
+ in `privy-pimlico-eip7702-example/app/components/WalletPanel.tsx`.
290
+
291
+ ### 0.1.2
292
+
293
+ - Initial public release. `handleQuote`, `handleSwap`,
294
+ `handlePerpDeposit` stateless handlers + `fetchPafiPools` subgraph
295
+ helper.
296
+
297
+ ---
298
+
237
299
  ## License
238
300
 
239
301
  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.3",
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"