@pafi-dev/core 0.5.3 → 0.5.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.
- package/dist/{chunk-YU7MFR6Y.cjs → chunk-B3PYJGTH.cjs} +14 -2
- package/dist/chunk-B3PYJGTH.cjs.map +1 -0
- package/dist/{chunk-CQCSQPWG.cjs → chunk-G6IUSI5S.cjs} +1 -1
- package/dist/{chunk-CQCSQPWG.cjs.map → chunk-G6IUSI5S.cjs.map} +1 -1
- package/dist/{chunk-QGO6X6LG.js → chunk-HZTR4RHR.js} +1 -1
- package/dist/chunk-HZTR4RHR.js.map +1 -0
- package/dist/{chunk-T6Y32SNK.js → chunk-MWKJODJE.js} +14 -2
- package/dist/{chunk-T6Y32SNK.js.map → chunk-MWKJODJE.js.map} +1 -1
- package/dist/contract/index.cjs +2 -2
- package/dist/contract/index.js +1 -1
- package/dist/index.cjs +43 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +27 -2
- package/dist/index.js.map +1 -1
- package/dist/swap/index.cjs +2 -2
- package/dist/swap/index.js +1 -1
- package/package.json +1 -1
- package/dist/abi/index.d.cts +0 -2194
- package/dist/abi/index.d.ts +0 -2194
- package/dist/auth/index.d.cts +0 -151
- package/dist/auth/index.d.ts +0 -151
- package/dist/chunk-QGO6X6LG.js.map +0 -1
- package/dist/chunk-YU7MFR6Y.cjs.map +0 -1
- package/dist/contract/index.d.cts +0 -22
- package/dist/contract/index.d.ts +0 -22
- package/dist/eip712/index.d.cts +0 -125
- package/dist/eip712/index.d.ts +0 -125
- package/dist/index-BEx-Q1bW.d.cts +0 -227
- package/dist/index-r4xCdQO7.d.ts +0 -227
- package/dist/index.d.cts +0 -1607
- package/dist/index.d.ts +0 -1607
- package/dist/quoting/index.d.cts +0 -59
- package/dist/quoting/index.d.ts +0 -59
- package/dist/swap/index.d.cts +0 -3
- package/dist/swap/index.d.ts +0 -3
- package/dist/types-b5_Tokjl.d.cts +0 -89
- package/dist/types-b5_Tokjl.d.ts +0 -89
package/dist/eip712/index.d.ts
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { b as PointTokenDomainConfig, M as MintRequest, E as EIP712Signature, S as SignatureVerification, c as BurnRequest, R as ReceiverConsent } from '../types-b5_Tokjl.js';
|
|
2
|
-
import { WalletClient, Hex, Address } from 'viem';
|
|
3
|
-
|
|
4
|
-
declare function buildDomain(config: PointTokenDomainConfig): {
|
|
5
|
-
name: string;
|
|
6
|
-
version: "1";
|
|
7
|
-
chainId: number;
|
|
8
|
-
verifyingContract: `0x${string}`;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Build the EIP-712 typed data object for a MintRequest.
|
|
13
|
-
* Returns the standard `{ domain, types, primaryType, message }` structure
|
|
14
|
-
* that any EIP-712 signer (viem, ethers, Privy, WalletConnect) can consume.
|
|
15
|
-
*/
|
|
16
|
-
declare function buildMintRequestTypedData(domain: PointTokenDomainConfig, message: MintRequest): {
|
|
17
|
-
domain: {
|
|
18
|
-
name: string;
|
|
19
|
-
version: "1";
|
|
20
|
-
chainId: number;
|
|
21
|
-
verifyingContract: `0x${string}`;
|
|
22
|
-
};
|
|
23
|
-
types: {
|
|
24
|
-
readonly MintRequest: readonly [{
|
|
25
|
-
readonly name: "to";
|
|
26
|
-
readonly type: "address";
|
|
27
|
-
}, {
|
|
28
|
-
readonly name: "amount";
|
|
29
|
-
readonly type: "uint256";
|
|
30
|
-
}, {
|
|
31
|
-
readonly name: "nonce";
|
|
32
|
-
readonly type: "uint256";
|
|
33
|
-
}, {
|
|
34
|
-
readonly name: "deadline";
|
|
35
|
-
readonly type: "uint256";
|
|
36
|
-
}];
|
|
37
|
-
};
|
|
38
|
-
primaryType: "MintRequest";
|
|
39
|
-
message: MintRequest;
|
|
40
|
-
};
|
|
41
|
-
declare function signMintRequest(walletClient: WalletClient, domain: PointTokenDomainConfig, message: MintRequest): Promise<EIP712Signature>;
|
|
42
|
-
declare function verifyMintRequest(domain: PointTokenDomainConfig, message: MintRequest, signature: Hex, expectedMinter: Address): Promise<SignatureVerification>;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* EIP-712 helpers for `BurnRequest` — consumed by the sig-gated burn
|
|
46
|
-
* path on `PointToken`:
|
|
47
|
-
*
|
|
48
|
-
* burn(address from, uint256 amount, uint256 deadline, bytes burnerSig)
|
|
49
|
-
*
|
|
50
|
-
* Solidity type hash:
|
|
51
|
-
* BurnRequest(address from,uint256 amount,uint256 nonce,uint256 deadline)
|
|
52
|
-
*
|
|
53
|
-
* Issuer backend signs with its burner signer (HSM/KMS). On-chain
|
|
54
|
-
* `msg.sender` must equal `from`, and the recovered signer must be in
|
|
55
|
-
* `burners[]`. Nonce comes from `burnRequestNonces[from]` and is
|
|
56
|
-
* auto-incremented on success.
|
|
57
|
-
*/
|
|
58
|
-
declare function buildBurnRequestTypedData(domain: PointTokenDomainConfig, message: BurnRequest): {
|
|
59
|
-
domain: {
|
|
60
|
-
name: string;
|
|
61
|
-
version: "1";
|
|
62
|
-
chainId: number;
|
|
63
|
-
verifyingContract: `0x${string}`;
|
|
64
|
-
};
|
|
65
|
-
types: {
|
|
66
|
-
readonly BurnRequest: readonly [{
|
|
67
|
-
readonly name: "from";
|
|
68
|
-
readonly type: "address";
|
|
69
|
-
}, {
|
|
70
|
-
readonly name: "amount";
|
|
71
|
-
readonly type: "uint256";
|
|
72
|
-
}, {
|
|
73
|
-
readonly name: "nonce";
|
|
74
|
-
readonly type: "uint256";
|
|
75
|
-
}, {
|
|
76
|
-
readonly name: "deadline";
|
|
77
|
-
readonly type: "uint256";
|
|
78
|
-
}];
|
|
79
|
-
};
|
|
80
|
-
primaryType: "BurnRequest";
|
|
81
|
-
message: BurnRequest;
|
|
82
|
-
};
|
|
83
|
-
declare function signBurnRequest(walletClient: WalletClient, domain: PointTokenDomainConfig, message: BurnRequest): Promise<EIP712Signature>;
|
|
84
|
-
declare function verifyBurnRequest(domain: PointTokenDomainConfig, message: BurnRequest, signature: Hex, expectedBurner: Address): Promise<SignatureVerification>;
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Build the EIP-712 typed data object for a ReceiverConsent.
|
|
88
|
-
* Returns the standard `{ domain, types, primaryType, message }` structure
|
|
89
|
-
* that any EIP-712 signer (viem, ethers, Privy, WalletConnect) can consume.
|
|
90
|
-
*/
|
|
91
|
-
declare function buildReceiverConsentTypedData(domain: PointTokenDomainConfig, message: ReceiverConsent): {
|
|
92
|
-
domain: {
|
|
93
|
-
name: string;
|
|
94
|
-
version: "1";
|
|
95
|
-
chainId: number;
|
|
96
|
-
verifyingContract: `0x${string}`;
|
|
97
|
-
};
|
|
98
|
-
types: {
|
|
99
|
-
readonly ReceiverConsent: readonly [{
|
|
100
|
-
readonly name: "onBehalfOf";
|
|
101
|
-
readonly type: "address";
|
|
102
|
-
}, {
|
|
103
|
-
readonly name: "originalReceiver";
|
|
104
|
-
readonly type: "address";
|
|
105
|
-
}, {
|
|
106
|
-
readonly name: "amount";
|
|
107
|
-
readonly type: "uint256";
|
|
108
|
-
}, {
|
|
109
|
-
readonly name: "nonce";
|
|
110
|
-
readonly type: "uint256";
|
|
111
|
-
}, {
|
|
112
|
-
readonly name: "deadline";
|
|
113
|
-
readonly type: "uint256";
|
|
114
|
-
}, {
|
|
115
|
-
readonly name: "extData";
|
|
116
|
-
readonly type: "bytes";
|
|
117
|
-
}];
|
|
118
|
-
};
|
|
119
|
-
primaryType: "ReceiverConsent";
|
|
120
|
-
message: ReceiverConsent;
|
|
121
|
-
};
|
|
122
|
-
declare function signReceiverConsent(walletClient: WalletClient, domain: PointTokenDomainConfig, message: ReceiverConsent): Promise<EIP712Signature>;
|
|
123
|
-
declare function verifyReceiverConsent(domain: PointTokenDomainConfig, message: ReceiverConsent, signature: Hex, expectedReceiver: Address): Promise<SignatureVerification>;
|
|
124
|
-
|
|
125
|
-
export { buildBurnRequestTypedData, buildDomain, buildMintRequestTypedData, buildReceiverConsentTypedData, signBurnRequest, signMintRequest, signReceiverConsent, verifyBurnRequest, verifyMintRequest, verifyReceiverConsent };
|
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
import { Address, Hex, PublicClient } from 'viem';
|
|
2
|
-
import { Q as QuoteResult, d as PathKey } from './types-b5_Tokjl.cjs';
|
|
3
|
-
|
|
4
|
-
declare function checkAllowance(client: PublicClient, token: Address, owner: Address, spender: Address): Promise<bigint>;
|
|
5
|
-
/**
|
|
6
|
-
* Encode an ERC-20 approve(spender, amount) call.
|
|
7
|
-
*/
|
|
8
|
-
declare function buildErc20ApprovalCalldata(spender: Address, amount: bigint): Hex;
|
|
9
|
-
/**
|
|
10
|
-
* Encode a Permit2 approve(token, spender, amount, expiration) call.
|
|
11
|
-
*/
|
|
12
|
-
declare function buildPermit2ApprovalCalldata(token: Address, spender: Address, amount: bigint, expiration: number): Hex;
|
|
13
|
-
|
|
14
|
-
/** UniversalRouter command byte for V4 swap */
|
|
15
|
-
declare const V4_SWAP: 16;
|
|
16
|
-
declare const SWAP_EXACT_IN: 7;
|
|
17
|
-
declare const SETTLE_ALL: 12;
|
|
18
|
-
declare const TAKE_ALL: 15;
|
|
19
|
-
/**
|
|
20
|
-
* Build the calldata inputs[0] (the V4_SWAP command payload) for
|
|
21
|
-
* UniversalRouter.execute.
|
|
22
|
-
*
|
|
23
|
-
* Actions encoded: SWAP_EXACT_IN → SETTLE_ALL → TAKE_ALL
|
|
24
|
-
*
|
|
25
|
-
* Encoding matches the Uniswap V4 SDK's V4Planner — each action's params
|
|
26
|
-
* are individually ABI-encoded, then wrapped together with the action bytes.
|
|
27
|
-
*/
|
|
28
|
-
declare function buildV4SwapInput(currencyIn: Address, path: PathKey[], amountIn: bigint, minAmountOut: bigint, outputCurrency: Address): Hex;
|
|
29
|
-
/**
|
|
30
|
-
* Build the full commands + inputs args for UniversalRouter.execute.
|
|
31
|
-
*/
|
|
32
|
-
declare function buildUniversalRouterExecuteArgs(currencyIn: Address, path: PathKey[], amountIn: bigint, minAmountOut: bigint, outputCurrency: Address): {
|
|
33
|
-
commands: Hex;
|
|
34
|
-
inputs: Hex[];
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
* Build UniversalRouter execute args from a quote result.
|
|
38
|
-
*
|
|
39
|
-
* Takes the output of `findBestQuote` / `quoteBestRoute` and produces
|
|
40
|
-
* ready-to-use `{ commands, inputs }` for `UniversalRouter.execute`.
|
|
41
|
-
*
|
|
42
|
-
* @param quote - Quote result containing the path
|
|
43
|
-
* @param currencyIn - Input token address
|
|
44
|
-
* @param currencyOut - Output token address
|
|
45
|
-
* @param amountIn - Exact input amount (same value passed to the quoter)
|
|
46
|
-
* @param minAmountOut - Minimum acceptable output (caller applies slippage)
|
|
47
|
-
*
|
|
48
|
-
* @deprecated Since v1.4 — the Issuer App no longer handles swaps.
|
|
49
|
-
* For the new PT→USDT batch call on PAFI Web (Scenario 4 with
|
|
50
|
-
* EIP-7702 gas deduction), use `buildSwapWithGasDeduction()` (v1.5).
|
|
51
|
-
* This helper is kept for legacy v0.2.x consumers; will be removed in v2.0.
|
|
52
|
-
*/
|
|
53
|
-
declare function buildSwapFromQuote(params: {
|
|
54
|
-
quote: QuoteResult;
|
|
55
|
-
currencyIn: Address;
|
|
56
|
-
currencyOut: Address;
|
|
57
|
-
amountIn: bigint;
|
|
58
|
-
minAmountOut: bigint;
|
|
59
|
-
}): {
|
|
60
|
-
commands: Hex;
|
|
61
|
-
inputs: Hex[];
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
interface SwapSimulationResult {
|
|
65
|
-
success: boolean;
|
|
66
|
-
gasEstimate: bigint;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Simulate a UniversalRouter.execute swap call via eth_call (no gas spent).
|
|
70
|
-
*
|
|
71
|
-
* Runs the full V4 swap flow — token transfer via Permit2, swap via
|
|
72
|
-
* PoolManager, output settlement — without submitting a transaction.
|
|
73
|
-
* If the simulation reverts, throws a `SimulationError` with the reason.
|
|
74
|
-
*
|
|
75
|
-
* @param client - viem PublicClient
|
|
76
|
-
* @param routerAddress - UniversalRouter contract address
|
|
77
|
-
* @param commands - Packed command bytes (from buildSwapFromQuote)
|
|
78
|
-
* @param inputs - Encoded inputs per command (from buildSwapFromQuote)
|
|
79
|
-
* @param deadline - Unix timestamp after which the tx expires
|
|
80
|
-
* @param from - Address that will execute the swap
|
|
81
|
-
*/
|
|
82
|
-
declare function simulateSwap(client: PublicClient, routerAddress: Address, commands: Hex, inputs: Hex[], deadline: bigint, from: Address): Promise<SwapSimulationResult>;
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* A single call inside a batch. `BatchExecutor.execute(Call[])` iterates
|
|
86
|
-
* and invokes each one. When the batch runs via EIP-7702 delegation,
|
|
87
|
-
* `msg.sender` for each call is the user's EOA.
|
|
88
|
-
*/
|
|
89
|
-
interface Operation {
|
|
90
|
-
target: Address;
|
|
91
|
-
value: bigint;
|
|
92
|
-
data: Hex;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Paymaster fields attached to a UserOperation. Populated by the
|
|
96
|
-
* Coinbase Paymaster (via PAFI Backend proxy) before the user signs.
|
|
97
|
-
*/
|
|
98
|
-
interface PaymasterFields {
|
|
99
|
-
paymaster: Address;
|
|
100
|
-
paymasterData: Hex;
|
|
101
|
-
paymasterVerificationGasLimit: bigint;
|
|
102
|
-
paymasterPostOpGasLimit: bigint;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Partial UserOp used during preparation — before paymaster fields are
|
|
106
|
-
* attached or the user signs.
|
|
107
|
-
*/
|
|
108
|
-
interface PartialUserOperation {
|
|
109
|
-
sender: Address;
|
|
110
|
-
nonce: bigint;
|
|
111
|
-
callData: Hex;
|
|
112
|
-
callGasLimit: bigint;
|
|
113
|
-
verificationGasLimit: bigint;
|
|
114
|
-
preVerificationGas: bigint;
|
|
115
|
-
maxFeePerGas: bigint;
|
|
116
|
-
maxPriorityFeePerGas: bigint;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Full ERC-4337 v0.7 UserOperation, ready for bundler submission.
|
|
120
|
-
*/
|
|
121
|
-
interface UserOperation extends PartialUserOperation {
|
|
122
|
-
paymaster: Address;
|
|
123
|
-
paymasterData: Hex;
|
|
124
|
-
paymasterVerificationGasLimit: bigint;
|
|
125
|
-
paymasterPostOpGasLimit: bigint;
|
|
126
|
-
signature: Hex;
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Receipt returned by a bundler after a UserOp lands on-chain.
|
|
130
|
-
*/
|
|
131
|
-
interface UserOpReceipt {
|
|
132
|
-
userOpHash: Hex;
|
|
133
|
-
success: boolean;
|
|
134
|
-
txHash: Hex;
|
|
135
|
-
blockNumber: bigint;
|
|
136
|
-
gasUsed: bigint;
|
|
137
|
-
/** Effective gas cost paid (wei). */
|
|
138
|
-
actualGasCost: bigint;
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Sentinel operation value used in tests + docs when `Operation.value`
|
|
142
|
-
* is irrelevant (ERC-20 transfers, for example).
|
|
143
|
-
*/
|
|
144
|
-
declare const ZERO_VALUE = 0n;
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* v1.5 — Scenario 4: Swap PT → USDT on PAFI Web with gas fee
|
|
148
|
-
* deducted in PT from the user's balance.
|
|
149
|
-
*
|
|
150
|
-
* Builds an unsigned `PartialUserOperation` that packages up to four
|
|
151
|
-
* inner calls into a single `BatchExecutor.execute(calls[])`:
|
|
152
|
-
*
|
|
153
|
-
* 1. `PT.approve(Permit2, amountIn)` — grant Permit2 ERC-20 allowance
|
|
154
|
-
* 2. `Permit2.approve(PT, router, amountIn, deadline)` — authorize
|
|
155
|
-
* the UniversalRouter to pull PT via Permit2
|
|
156
|
-
* 3. `UniversalRouter.execute(commands, inputs, deadline)` — V4 swap
|
|
157
|
-
* PT → USDT; user receives ≥ `minAmountOut` USDT
|
|
158
|
-
* 4. `PT.transfer(feeRecipient, gasFeePt)` — pay the operator back
|
|
159
|
-
* for sponsoring the gas, in PT (omitted when `gasFeePt` is 0)
|
|
160
|
-
*
|
|
161
|
-
* The user's wallet must hold `amountIn + gasFeePt` PT before the
|
|
162
|
-
* UserOp runs. All inner calls execute atomically via EIP-7702
|
|
163
|
-
* delegation (`msg.sender = user`), so a reverting swap unwinds
|
|
164
|
-
* the approvals and fee transfer too.
|
|
165
|
-
*
|
|
166
|
-
* ## Fee model
|
|
167
|
-
*
|
|
168
|
-
* The gas fee is a separate `transfer` after the swap — it does NOT
|
|
169
|
-
* come out of the USDT output, because that output goes straight to
|
|
170
|
-
* the user's wallet with no intermediate hook.
|
|
171
|
-
*
|
|
172
|
-
* If the FE wants "user receives exactly X USDT after gas":
|
|
173
|
-
* 1. Quote PT→USDT for candidate `amountIn` values
|
|
174
|
-
* 2. Pick an `amountIn` where `minAmountOut ≈ X`
|
|
175
|
-
* 3. Separately compute `gasFeePt` from the operator's rate
|
|
176
|
-
* 4. Ensure user's PT balance ≥ `amountIn + gasFeePt`
|
|
177
|
-
*
|
|
178
|
-
* ## Order of operations
|
|
179
|
-
*
|
|
180
|
-
* Fee transfer is last so a reverting swap also refunds the fee
|
|
181
|
-
* (atomic batch revert semantics).
|
|
182
|
-
*/
|
|
183
|
-
interface BuildSwapWithGasDeductionParams {
|
|
184
|
-
/** User's EOA (with EIP-7702 delegation to BatchExecutor). */
|
|
185
|
-
userAddress: Address;
|
|
186
|
-
/** ERC-4337 account nonce — fetched from EntryPoint by the caller. */
|
|
187
|
-
aaNonce: bigint;
|
|
188
|
-
/** PT token address being swapped. */
|
|
189
|
-
pointTokenAddress: Address;
|
|
190
|
-
/** Destination currency (typically USDT). */
|
|
191
|
-
outputTokenAddress: Address;
|
|
192
|
-
/** UniversalRouter contract address (chain-specific). */
|
|
193
|
-
universalRouterAddress: Address;
|
|
194
|
-
/** PT units to swap. User's balance must be ≥ `amountIn + gasFeePt`. */
|
|
195
|
-
amountIn: bigint;
|
|
196
|
-
/**
|
|
197
|
-
* Minimum USDT to accept out of the swap. Caller applies slippage
|
|
198
|
-
* (typically ~0.5-1%) against a fresh quote. Sub-minimum swap reverts.
|
|
199
|
-
*/
|
|
200
|
-
minAmountOut: bigint;
|
|
201
|
-
/** V4 pool path for the swap. Single-hop = 1 PathKey. */
|
|
202
|
-
swapPath: PathKey[];
|
|
203
|
-
/** Unix seconds. After this, the router rejects the swap. */
|
|
204
|
-
deadline: bigint;
|
|
205
|
-
/** PT amount transferred to `feeRecipient` as gas fee recovery. */
|
|
206
|
-
gasFeePt: bigint;
|
|
207
|
-
/** Where the gas fee lands — typically the operator or fee collector. */
|
|
208
|
-
feeRecipient: Address;
|
|
209
|
-
/** Override ERC-4337 gas estimates. Defaults are conservative; tune down for cheaper UserOps. */
|
|
210
|
-
gasLimits?: {
|
|
211
|
-
callGasLimit?: bigint;
|
|
212
|
-
verificationGasLimit?: bigint;
|
|
213
|
-
preVerificationGas?: bigint;
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Build an unsigned UserOp for Scenario 4. Returns a
|
|
218
|
-
* `PartialUserOperation` — caller attaches paymaster sponsorship (via
|
|
219
|
-
* `POST /api/paymaster/sponsor`), adds the user's UserOp-hash
|
|
220
|
-
* signature, and submits to the Bundler.
|
|
221
|
-
*
|
|
222
|
-
* @throws when `amountIn` or `gasFeePt` is not positive, or when
|
|
223
|
-
* `swapPath` is empty (at least one PathKey required).
|
|
224
|
-
*/
|
|
225
|
-
declare function buildSwapWithGasDeduction(params: BuildSwapWithGasDeductionParams): PartialUserOperation;
|
|
226
|
-
|
|
227
|
-
export { type BuildSwapWithGasDeductionParams as B, type Operation as O, type PartialUserOperation as P, type SwapSimulationResult as S, TAKE_ALL as T, type UserOperation as U, V4_SWAP as V, ZERO_VALUE as Z, type PaymasterFields as a, SETTLE_ALL as b, SWAP_EXACT_IN as c, type UserOpReceipt as d, buildErc20ApprovalCalldata as e, buildPermit2ApprovalCalldata as f, buildSwapFromQuote as g, buildSwapWithGasDeduction as h, buildUniversalRouterExecuteArgs as i, buildV4SwapInput as j, checkAllowance as k, simulateSwap as s };
|
package/dist/index-r4xCdQO7.d.ts
DELETED
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
import { Address, Hex, PublicClient } from 'viem';
|
|
2
|
-
import { Q as QuoteResult, d as PathKey } from './types-b5_Tokjl.js';
|
|
3
|
-
|
|
4
|
-
declare function checkAllowance(client: PublicClient, token: Address, owner: Address, spender: Address): Promise<bigint>;
|
|
5
|
-
/**
|
|
6
|
-
* Encode an ERC-20 approve(spender, amount) call.
|
|
7
|
-
*/
|
|
8
|
-
declare function buildErc20ApprovalCalldata(spender: Address, amount: bigint): Hex;
|
|
9
|
-
/**
|
|
10
|
-
* Encode a Permit2 approve(token, spender, amount, expiration) call.
|
|
11
|
-
*/
|
|
12
|
-
declare function buildPermit2ApprovalCalldata(token: Address, spender: Address, amount: bigint, expiration: number): Hex;
|
|
13
|
-
|
|
14
|
-
/** UniversalRouter command byte for V4 swap */
|
|
15
|
-
declare const V4_SWAP: 16;
|
|
16
|
-
declare const SWAP_EXACT_IN: 7;
|
|
17
|
-
declare const SETTLE_ALL: 12;
|
|
18
|
-
declare const TAKE_ALL: 15;
|
|
19
|
-
/**
|
|
20
|
-
* Build the calldata inputs[0] (the V4_SWAP command payload) for
|
|
21
|
-
* UniversalRouter.execute.
|
|
22
|
-
*
|
|
23
|
-
* Actions encoded: SWAP_EXACT_IN → SETTLE_ALL → TAKE_ALL
|
|
24
|
-
*
|
|
25
|
-
* Encoding matches the Uniswap V4 SDK's V4Planner — each action's params
|
|
26
|
-
* are individually ABI-encoded, then wrapped together with the action bytes.
|
|
27
|
-
*/
|
|
28
|
-
declare function buildV4SwapInput(currencyIn: Address, path: PathKey[], amountIn: bigint, minAmountOut: bigint, outputCurrency: Address): Hex;
|
|
29
|
-
/**
|
|
30
|
-
* Build the full commands + inputs args for UniversalRouter.execute.
|
|
31
|
-
*/
|
|
32
|
-
declare function buildUniversalRouterExecuteArgs(currencyIn: Address, path: PathKey[], amountIn: bigint, minAmountOut: bigint, outputCurrency: Address): {
|
|
33
|
-
commands: Hex;
|
|
34
|
-
inputs: Hex[];
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
* Build UniversalRouter execute args from a quote result.
|
|
38
|
-
*
|
|
39
|
-
* Takes the output of `findBestQuote` / `quoteBestRoute` and produces
|
|
40
|
-
* ready-to-use `{ commands, inputs }` for `UniversalRouter.execute`.
|
|
41
|
-
*
|
|
42
|
-
* @param quote - Quote result containing the path
|
|
43
|
-
* @param currencyIn - Input token address
|
|
44
|
-
* @param currencyOut - Output token address
|
|
45
|
-
* @param amountIn - Exact input amount (same value passed to the quoter)
|
|
46
|
-
* @param minAmountOut - Minimum acceptable output (caller applies slippage)
|
|
47
|
-
*
|
|
48
|
-
* @deprecated Since v1.4 — the Issuer App no longer handles swaps.
|
|
49
|
-
* For the new PT→USDT batch call on PAFI Web (Scenario 4 with
|
|
50
|
-
* EIP-7702 gas deduction), use `buildSwapWithGasDeduction()` (v1.5).
|
|
51
|
-
* This helper is kept for legacy v0.2.x consumers; will be removed in v2.0.
|
|
52
|
-
*/
|
|
53
|
-
declare function buildSwapFromQuote(params: {
|
|
54
|
-
quote: QuoteResult;
|
|
55
|
-
currencyIn: Address;
|
|
56
|
-
currencyOut: Address;
|
|
57
|
-
amountIn: bigint;
|
|
58
|
-
minAmountOut: bigint;
|
|
59
|
-
}): {
|
|
60
|
-
commands: Hex;
|
|
61
|
-
inputs: Hex[];
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
interface SwapSimulationResult {
|
|
65
|
-
success: boolean;
|
|
66
|
-
gasEstimate: bigint;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Simulate a UniversalRouter.execute swap call via eth_call (no gas spent).
|
|
70
|
-
*
|
|
71
|
-
* Runs the full V4 swap flow — token transfer via Permit2, swap via
|
|
72
|
-
* PoolManager, output settlement — without submitting a transaction.
|
|
73
|
-
* If the simulation reverts, throws a `SimulationError` with the reason.
|
|
74
|
-
*
|
|
75
|
-
* @param client - viem PublicClient
|
|
76
|
-
* @param routerAddress - UniversalRouter contract address
|
|
77
|
-
* @param commands - Packed command bytes (from buildSwapFromQuote)
|
|
78
|
-
* @param inputs - Encoded inputs per command (from buildSwapFromQuote)
|
|
79
|
-
* @param deadline - Unix timestamp after which the tx expires
|
|
80
|
-
* @param from - Address that will execute the swap
|
|
81
|
-
*/
|
|
82
|
-
declare function simulateSwap(client: PublicClient, routerAddress: Address, commands: Hex, inputs: Hex[], deadline: bigint, from: Address): Promise<SwapSimulationResult>;
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* A single call inside a batch. `BatchExecutor.execute(Call[])` iterates
|
|
86
|
-
* and invokes each one. When the batch runs via EIP-7702 delegation,
|
|
87
|
-
* `msg.sender` for each call is the user's EOA.
|
|
88
|
-
*/
|
|
89
|
-
interface Operation {
|
|
90
|
-
target: Address;
|
|
91
|
-
value: bigint;
|
|
92
|
-
data: Hex;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Paymaster fields attached to a UserOperation. Populated by the
|
|
96
|
-
* Coinbase Paymaster (via PAFI Backend proxy) before the user signs.
|
|
97
|
-
*/
|
|
98
|
-
interface PaymasterFields {
|
|
99
|
-
paymaster: Address;
|
|
100
|
-
paymasterData: Hex;
|
|
101
|
-
paymasterVerificationGasLimit: bigint;
|
|
102
|
-
paymasterPostOpGasLimit: bigint;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Partial UserOp used during preparation — before paymaster fields are
|
|
106
|
-
* attached or the user signs.
|
|
107
|
-
*/
|
|
108
|
-
interface PartialUserOperation {
|
|
109
|
-
sender: Address;
|
|
110
|
-
nonce: bigint;
|
|
111
|
-
callData: Hex;
|
|
112
|
-
callGasLimit: bigint;
|
|
113
|
-
verificationGasLimit: bigint;
|
|
114
|
-
preVerificationGas: bigint;
|
|
115
|
-
maxFeePerGas: bigint;
|
|
116
|
-
maxPriorityFeePerGas: bigint;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Full ERC-4337 v0.7 UserOperation, ready for bundler submission.
|
|
120
|
-
*/
|
|
121
|
-
interface UserOperation extends PartialUserOperation {
|
|
122
|
-
paymaster: Address;
|
|
123
|
-
paymasterData: Hex;
|
|
124
|
-
paymasterVerificationGasLimit: bigint;
|
|
125
|
-
paymasterPostOpGasLimit: bigint;
|
|
126
|
-
signature: Hex;
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Receipt returned by a bundler after a UserOp lands on-chain.
|
|
130
|
-
*/
|
|
131
|
-
interface UserOpReceipt {
|
|
132
|
-
userOpHash: Hex;
|
|
133
|
-
success: boolean;
|
|
134
|
-
txHash: Hex;
|
|
135
|
-
blockNumber: bigint;
|
|
136
|
-
gasUsed: bigint;
|
|
137
|
-
/** Effective gas cost paid (wei). */
|
|
138
|
-
actualGasCost: bigint;
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Sentinel operation value used in tests + docs when `Operation.value`
|
|
142
|
-
* is irrelevant (ERC-20 transfers, for example).
|
|
143
|
-
*/
|
|
144
|
-
declare const ZERO_VALUE = 0n;
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* v1.5 — Scenario 4: Swap PT → USDT on PAFI Web with gas fee
|
|
148
|
-
* deducted in PT from the user's balance.
|
|
149
|
-
*
|
|
150
|
-
* Builds an unsigned `PartialUserOperation` that packages up to four
|
|
151
|
-
* inner calls into a single `BatchExecutor.execute(calls[])`:
|
|
152
|
-
*
|
|
153
|
-
* 1. `PT.approve(Permit2, amountIn)` — grant Permit2 ERC-20 allowance
|
|
154
|
-
* 2. `Permit2.approve(PT, router, amountIn, deadline)` — authorize
|
|
155
|
-
* the UniversalRouter to pull PT via Permit2
|
|
156
|
-
* 3. `UniversalRouter.execute(commands, inputs, deadline)` — V4 swap
|
|
157
|
-
* PT → USDT; user receives ≥ `minAmountOut` USDT
|
|
158
|
-
* 4. `PT.transfer(feeRecipient, gasFeePt)` — pay the operator back
|
|
159
|
-
* for sponsoring the gas, in PT (omitted when `gasFeePt` is 0)
|
|
160
|
-
*
|
|
161
|
-
* The user's wallet must hold `amountIn + gasFeePt` PT before the
|
|
162
|
-
* UserOp runs. All inner calls execute atomically via EIP-7702
|
|
163
|
-
* delegation (`msg.sender = user`), so a reverting swap unwinds
|
|
164
|
-
* the approvals and fee transfer too.
|
|
165
|
-
*
|
|
166
|
-
* ## Fee model
|
|
167
|
-
*
|
|
168
|
-
* The gas fee is a separate `transfer` after the swap — it does NOT
|
|
169
|
-
* come out of the USDT output, because that output goes straight to
|
|
170
|
-
* the user's wallet with no intermediate hook.
|
|
171
|
-
*
|
|
172
|
-
* If the FE wants "user receives exactly X USDT after gas":
|
|
173
|
-
* 1. Quote PT→USDT for candidate `amountIn` values
|
|
174
|
-
* 2. Pick an `amountIn` where `minAmountOut ≈ X`
|
|
175
|
-
* 3. Separately compute `gasFeePt` from the operator's rate
|
|
176
|
-
* 4. Ensure user's PT balance ≥ `amountIn + gasFeePt`
|
|
177
|
-
*
|
|
178
|
-
* ## Order of operations
|
|
179
|
-
*
|
|
180
|
-
* Fee transfer is last so a reverting swap also refunds the fee
|
|
181
|
-
* (atomic batch revert semantics).
|
|
182
|
-
*/
|
|
183
|
-
interface BuildSwapWithGasDeductionParams {
|
|
184
|
-
/** User's EOA (with EIP-7702 delegation to BatchExecutor). */
|
|
185
|
-
userAddress: Address;
|
|
186
|
-
/** ERC-4337 account nonce — fetched from EntryPoint by the caller. */
|
|
187
|
-
aaNonce: bigint;
|
|
188
|
-
/** PT token address being swapped. */
|
|
189
|
-
pointTokenAddress: Address;
|
|
190
|
-
/** Destination currency (typically USDT). */
|
|
191
|
-
outputTokenAddress: Address;
|
|
192
|
-
/** UniversalRouter contract address (chain-specific). */
|
|
193
|
-
universalRouterAddress: Address;
|
|
194
|
-
/** PT units to swap. User's balance must be ≥ `amountIn + gasFeePt`. */
|
|
195
|
-
amountIn: bigint;
|
|
196
|
-
/**
|
|
197
|
-
* Minimum USDT to accept out of the swap. Caller applies slippage
|
|
198
|
-
* (typically ~0.5-1%) against a fresh quote. Sub-minimum swap reverts.
|
|
199
|
-
*/
|
|
200
|
-
minAmountOut: bigint;
|
|
201
|
-
/** V4 pool path for the swap. Single-hop = 1 PathKey. */
|
|
202
|
-
swapPath: PathKey[];
|
|
203
|
-
/** Unix seconds. After this, the router rejects the swap. */
|
|
204
|
-
deadline: bigint;
|
|
205
|
-
/** PT amount transferred to `feeRecipient` as gas fee recovery. */
|
|
206
|
-
gasFeePt: bigint;
|
|
207
|
-
/** Where the gas fee lands — typically the operator or fee collector. */
|
|
208
|
-
feeRecipient: Address;
|
|
209
|
-
/** Override ERC-4337 gas estimates. Defaults are conservative; tune down for cheaper UserOps. */
|
|
210
|
-
gasLimits?: {
|
|
211
|
-
callGasLimit?: bigint;
|
|
212
|
-
verificationGasLimit?: bigint;
|
|
213
|
-
preVerificationGas?: bigint;
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Build an unsigned UserOp for Scenario 4. Returns a
|
|
218
|
-
* `PartialUserOperation` — caller attaches paymaster sponsorship (via
|
|
219
|
-
* `POST /api/paymaster/sponsor`), adds the user's UserOp-hash
|
|
220
|
-
* signature, and submits to the Bundler.
|
|
221
|
-
*
|
|
222
|
-
* @throws when `amountIn` or `gasFeePt` is not positive, or when
|
|
223
|
-
* `swapPath` is empty (at least one PathKey required).
|
|
224
|
-
*/
|
|
225
|
-
declare function buildSwapWithGasDeduction(params: BuildSwapWithGasDeductionParams): PartialUserOperation;
|
|
226
|
-
|
|
227
|
-
export { type BuildSwapWithGasDeductionParams as B, type Operation as O, type PartialUserOperation as P, type SwapSimulationResult as S, TAKE_ALL as T, type UserOperation as U, V4_SWAP as V, ZERO_VALUE as Z, type PaymasterFields as a, SETTLE_ALL as b, SWAP_EXACT_IN as c, type UserOpReceipt as d, buildErc20ApprovalCalldata as e, buildPermit2ApprovalCalldata as f, buildSwapFromQuote as g, buildSwapWithGasDeduction as h, buildUniversalRouterExecuteArgs as i, buildV4SwapInput as j, checkAllowance as k, simulateSwap as s };
|