@pafi-dev/trading 0.3.3 → 0.4.1
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/README.md +95 -0
- package/dist/index.cjs +840 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +541 -19
- package/dist/index.d.ts +541 -19
- package/dist/index.js +854 -14
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -187,6 +187,99 @@ simulations.
|
|
|
187
187
|
|
|
188
188
|
---
|
|
189
189
|
|
|
190
|
+
## Direct path — no AA, no bundler, no sponsor-relayer
|
|
191
|
+
|
|
192
|
+
`v0.4.0+` ships `swapDirect()` + `perpDepositDirect()` for the FE-only
|
|
193
|
+
flow where the user pays gas in ETH and broadcasts a single type-2 tx
|
|
194
|
+
calling its own EIP-7702 delegated bytecode. No Pimlico API key, no
|
|
195
|
+
sponsor-relayer, no PAFI infra.
|
|
196
|
+
|
|
197
|
+
**Precondition:** user EOA must already be EIP-7702 delegated (run
|
|
198
|
+
`delegateDirect()` from `@pafi-dev/core` first; both helpers throw a
|
|
199
|
+
clear error otherwise).
|
|
200
|
+
|
|
201
|
+
### `swapDirect`
|
|
202
|
+
|
|
203
|
+
```ts
|
|
204
|
+
import { swapDirect, fetchPafiPools } from "@pafi-dev/trading";
|
|
205
|
+
import { createPublicClient, createWalletClient, custom, http, parseUnits } from "viem";
|
|
206
|
+
import { base } from "viem/chains";
|
|
207
|
+
|
|
208
|
+
const publicClient = createPublicClient({ chain: base, transport: http() });
|
|
209
|
+
// `walletClient` from Privy embedded wallet, MetaMask, etc.
|
|
210
|
+
const walletClient = createWalletClient({
|
|
211
|
+
account: wallet.address,
|
|
212
|
+
chain: base,
|
|
213
|
+
transport: custom(await wallet.getEthereumProvider()),
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
const pools = await fetchPafiPools(8453, POINT_TOKEN);
|
|
217
|
+
|
|
218
|
+
const result = await swapDirect({
|
|
219
|
+
userAddress: wallet.address,
|
|
220
|
+
chainId: 8453,
|
|
221
|
+
inputTokenAddress: POINT_TOKEN,
|
|
222
|
+
outputTokenAddress: USDT,
|
|
223
|
+
amount: parseUnits("100", 18),
|
|
224
|
+
pools,
|
|
225
|
+
publicClient,
|
|
226
|
+
walletClient,
|
|
227
|
+
// optional: slippageBps, deadline, gasFeeAmountOutput, waitForReceipt
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
console.log("Swap tx:", result.txHash);
|
|
231
|
+
// {
|
|
232
|
+
// txHash, receipt?, estimatedOutputAmount, minAmountOut, hops,
|
|
233
|
+
// deadline, feeAmountUsed
|
|
234
|
+
// }
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
**Operator fee:** default `0n` (skip — PAFI not sponsoring this swap).
|
|
238
|
+
Pass an explicit `gasFeeAmountOutput: bigint` only if you want to mirror
|
|
239
|
+
the sponsored flow's fee transfer.
|
|
240
|
+
|
|
241
|
+
### `perpDepositDirect`
|
|
242
|
+
|
|
243
|
+
```ts
|
|
244
|
+
import { perpDepositDirect } from "@pafi-dev/trading";
|
|
245
|
+
|
|
246
|
+
const result = await perpDepositDirect({
|
|
247
|
+
userAddress: wallet.address,
|
|
248
|
+
chainId: 8453,
|
|
249
|
+
amount: parseUnits("10", 6), // 10 USDC
|
|
250
|
+
brokerId: "orderly", // | "woofi_pro" | "logx"
|
|
251
|
+
publicClient,
|
|
252
|
+
walletClient,
|
|
253
|
+
// optional: maxRelayFee, gasFeeUsdc, waitForReceipt
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
// {
|
|
257
|
+
// txHash, receipt?, relayTokenFee, maxFee, netDeposit,
|
|
258
|
+
// feeAmountUsed, accountId, brokerHash, usdcAddress, relayAddress
|
|
259
|
+
// }
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
The Relay still charges its own USDC fee (`Relay.quoteTokenFee`) to
|
|
263
|
+
cover LayerZero `msg.value`; that's separate from PAFI's operator fee
|
|
264
|
+
(which is skipped by default on the direct path).
|
|
265
|
+
|
|
266
|
+
### When to use direct vs. AA path
|
|
267
|
+
|
|
268
|
+
| Aspect | `swapDirect` / `perpDepositDirect` | `TradingHandlers.handleSwap` / `handlePerpDeposit` |
|
|
269
|
+
| --- | --- | --- |
|
|
270
|
+
| User pays gas | ETH (native) | Free (sponsor) or ETH (fallback) |
|
|
271
|
+
| Bundler required | No | Yes (Pimlico) |
|
|
272
|
+
| Sponsor-relayer required | No | Yes (sponsored path) |
|
|
273
|
+
| Operator fee charged | Default skip | Default included |
|
|
274
|
+
| Round trips | 1 (broadcast tx) | 2+ (paymaster + bundler) |
|
|
275
|
+
| Precondition | EIP-7702 delegated | Same |
|
|
276
|
+
|
|
277
|
+
Use direct for FE dev/test, integrations without a Pimlico key, or
|
|
278
|
+
production paths where users explicitly opt to pay gas. Use AA path for
|
|
279
|
+
the production gas-free UX via sponsor-relayer.
|
|
280
|
+
|
|
281
|
+
---
|
|
282
|
+
|
|
190
283
|
## API reference
|
|
191
284
|
|
|
192
285
|
### `TradingHandlers`
|
|
@@ -213,6 +306,8 @@ Methods:
|
|
|
213
306
|
- `buildPermit2ApprovalCalldata`, `buildErc20ApprovalCalldata`, `checkAllowance`
|
|
214
307
|
- `simulateSwap` — `eth_call` dry-run
|
|
215
308
|
- `fetchPafiPools(chainId, pointTokenAddress, subgraphUrl?)`
|
|
309
|
+
- `swapDirect(params)` — FE-direct swap (no AA, user pays gas) — see "Direct path" section
|
|
310
|
+
- `perpDepositDirect(params)` — FE-direct perp deposit (no AA, user pays gas)
|
|
216
311
|
|
|
217
312
|
---
|
|
218
313
|
|