@pafi-dev/core 0.5.22 → 0.6.0
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/abi/index.cjs +3 -7
- package/dist/abi/index.cjs.map +1 -1
- package/dist/abi/index.js +6 -10
- package/dist/chunk-3QDZFDEL.cjs +223 -0
- package/dist/chunk-3QDZFDEL.cjs.map +1 -0
- package/dist/{chunk-Y2MZ7MKJ.js → chunk-6CXTFOIH.js} +196 -2
- package/dist/chunk-6CXTFOIH.js.map +1 -0
- package/dist/{chunk-R6OFGVMP.cjs → chunk-Q6WCDZXI.cjs} +196 -2
- package/dist/chunk-Q6WCDZXI.cjs.map +1 -0
- package/dist/{chunk-TXA4GK5C.js → chunk-UOKI5GG6.js} +87 -7
- package/dist/chunk-UOKI5GG6.js.map +1 -0
- package/dist/eip712/index.cjs +2 -3
- package/dist/eip712/index.cjs.map +1 -1
- package/dist/eip712/index.js +1 -2
- package/dist/index.cjs +184 -168
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +69 -48
- package/dist/index.d.ts +69 -48
- package/dist/index.js +164 -148
- package/dist/index.js.map +1 -1
- package/package.json +1 -31
- package/dist/chunk-2PIXFXA2.js +0 -135
- package/dist/chunk-2PIXFXA2.js.map +0 -1
- package/dist/chunk-CL3QSI4O.cjs +0 -65
- package/dist/chunk-CL3QSI4O.cjs.map +0 -1
- package/dist/chunk-DX73FB4P.cjs +0 -143
- package/dist/chunk-DX73FB4P.cjs.map +0 -1
- package/dist/chunk-IPXARZ6F.cjs +0 -135
- package/dist/chunk-IPXARZ6F.cjs.map +0 -1
- package/dist/chunk-JJ2LGENO.cjs +0 -373
- package/dist/chunk-JJ2LGENO.cjs.map +0 -1
- package/dist/chunk-KFWZRL7I.js +0 -65
- package/dist/chunk-KFWZRL7I.js.map +0 -1
- package/dist/chunk-L5UHQQVC.cjs +0 -136
- package/dist/chunk-L5UHQQVC.cjs.map +0 -1
- package/dist/chunk-R6OFGVMP.cjs.map +0 -1
- package/dist/chunk-TXA4GK5C.js.map +0 -1
- package/dist/chunk-VG23GIWQ.js +0 -373
- package/dist/chunk-VG23GIWQ.js.map +0 -1
- package/dist/chunk-WAFUL62X.js +0 -136
- package/dist/chunk-WAFUL62X.js.map +0 -1
- package/dist/chunk-X2JZFK4C.cjs +0 -87
- package/dist/chunk-X2JZFK4C.cjs.map +0 -1
- package/dist/chunk-Y2MZ7MKJ.js.map +0 -1
- package/dist/chunk-Y3HMGOYW.js +0 -87
- package/dist/chunk-Y3HMGOYW.js.map +0 -1
- package/dist/index-3C_HdEIm.d.cts +0 -227
- package/dist/index-DKtVEoRC.d.ts +0 -227
- package/dist/quoting/index.cjs +0 -19
- package/dist/quoting/index.cjs.map +0 -1
- package/dist/quoting/index.d.cts +0 -59
- package/dist/quoting/index.d.ts +0 -59
- package/dist/quoting/index.js +0 -19
- package/dist/quoting/index.js.map +0 -1
- package/dist/swap/index.cjs +0 -31
- package/dist/swap/index.cjs.map +0 -1
- package/dist/swap/index.d.cts +0 -3
- package/dist/swap/index.d.ts +0 -3
- package/dist/swap/index.js +0 -31
- package/dist/swap/index.js.map +0 -1
package/dist/chunk-JJ2LGENO.cjs
DELETED
|
@@ -1,373 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var _chunkIPXARZ6Fcjs = require('./chunk-IPXARZ6F.cjs');
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var _chunkX2JZFK4Ccjs = require('./chunk-X2JZFK4C.cjs');
|
|
9
|
-
|
|
10
|
-
// src/swap/approval.ts
|
|
11
|
-
var _viem = require('viem');
|
|
12
|
-
async function checkAllowance(client, token, owner, spender) {
|
|
13
|
-
return client.readContract({
|
|
14
|
-
address: token,
|
|
15
|
-
abi: _chunkIPXARZ6Fcjs.erc20Abi,
|
|
16
|
-
functionName: "allowance",
|
|
17
|
-
args: [owner, spender]
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
function buildErc20ApprovalCalldata(spender, amount) {
|
|
21
|
-
return _viem.encodeFunctionData.call(void 0, {
|
|
22
|
-
abi: _chunkIPXARZ6Fcjs.erc20Abi,
|
|
23
|
-
functionName: "approve",
|
|
24
|
-
args: [spender, amount]
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
function buildPermit2ApprovalCalldata(token, spender, amount, expiration) {
|
|
28
|
-
return _viem.encodeFunctionData.call(void 0, {
|
|
29
|
-
abi: _chunkIPXARZ6Fcjs.permit2Abi,
|
|
30
|
-
functionName: "approve",
|
|
31
|
-
args: [token, spender, amount, expiration]
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// src/swap/universalRouter.ts
|
|
36
|
-
|
|
37
|
-
var V4_SWAP = 16;
|
|
38
|
-
var SWAP_EXACT_IN = 7;
|
|
39
|
-
var SETTLE_ALL = 12;
|
|
40
|
-
var TAKE_ALL = 15;
|
|
41
|
-
var PATH_KEY_ABI_COMPONENTS = [
|
|
42
|
-
{ name: "intermediateCurrency", type: "address" },
|
|
43
|
-
{ name: "fee", type: "uint256" },
|
|
44
|
-
{ name: "tickSpacing", type: "int24" },
|
|
45
|
-
{ name: "hooks", type: "address" },
|
|
46
|
-
{ name: "hookData", type: "bytes" }
|
|
47
|
-
];
|
|
48
|
-
var EXACT_INPUT_PARAMS_ABI = [
|
|
49
|
-
{ name: "currencyIn", type: "address" },
|
|
50
|
-
{
|
|
51
|
-
name: "path",
|
|
52
|
-
type: "tuple[]",
|
|
53
|
-
components: PATH_KEY_ABI_COMPONENTS
|
|
54
|
-
},
|
|
55
|
-
{ name: "amountIn", type: "uint128" },
|
|
56
|
-
{ name: "amountOutMinimum", type: "uint128" }
|
|
57
|
-
];
|
|
58
|
-
function buildV4SwapInput(currencyIn, path, amountIn, minAmountOut, outputCurrency) {
|
|
59
|
-
const actions = _viem.encodePacked.call(void 0,
|
|
60
|
-
["uint8", "uint8", "uint8"],
|
|
61
|
-
[SWAP_EXACT_IN, SETTLE_ALL, TAKE_ALL]
|
|
62
|
-
);
|
|
63
|
-
const swapParam = _viem.encodeAbiParameters.call(void 0,
|
|
64
|
-
[{ name: "swap", type: "tuple", components: EXACT_INPUT_PARAMS_ABI }],
|
|
65
|
-
[
|
|
66
|
-
{
|
|
67
|
-
currencyIn,
|
|
68
|
-
path: path.map((p) => ({
|
|
69
|
-
intermediateCurrency: p.intermediateCurrency,
|
|
70
|
-
fee: BigInt(p.fee),
|
|
71
|
-
tickSpacing: p.tickSpacing,
|
|
72
|
-
hooks: p.hooks,
|
|
73
|
-
hookData: p.hookData
|
|
74
|
-
})),
|
|
75
|
-
amountIn,
|
|
76
|
-
amountOutMinimum: minAmountOut
|
|
77
|
-
}
|
|
78
|
-
]
|
|
79
|
-
);
|
|
80
|
-
const settleParam = _viem.encodeAbiParameters.call(void 0,
|
|
81
|
-
[
|
|
82
|
-
{ name: "currency", type: "address" },
|
|
83
|
-
{ name: "maxAmount", type: "uint256" }
|
|
84
|
-
],
|
|
85
|
-
[currencyIn, amountIn]
|
|
86
|
-
);
|
|
87
|
-
const takeParam = _viem.encodeAbiParameters.call(void 0,
|
|
88
|
-
[
|
|
89
|
-
{ name: "currency", type: "address" },
|
|
90
|
-
{ name: "minAmount", type: "uint256" }
|
|
91
|
-
],
|
|
92
|
-
[outputCurrency, minAmountOut]
|
|
93
|
-
);
|
|
94
|
-
return _viem.encodeAbiParameters.call(void 0,
|
|
95
|
-
[
|
|
96
|
-
{ name: "actions", type: "bytes" },
|
|
97
|
-
{ name: "params", type: "bytes[]" }
|
|
98
|
-
],
|
|
99
|
-
[actions, [swapParam, settleParam, takeParam]]
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
function buildUniversalRouterExecuteArgs(currencyIn, path, amountIn, minAmountOut, outputCurrency) {
|
|
103
|
-
const commands = _viem.encodePacked.call(void 0, ["uint8"], [V4_SWAP]);
|
|
104
|
-
const inputs = [
|
|
105
|
-
buildV4SwapInput(currencyIn, path, amountIn, minAmountOut, outputCurrency)
|
|
106
|
-
];
|
|
107
|
-
return { commands, inputs };
|
|
108
|
-
}
|
|
109
|
-
function buildSwapFromQuote(params) {
|
|
110
|
-
return buildUniversalRouterExecuteArgs(
|
|
111
|
-
params.currencyIn,
|
|
112
|
-
params.quote.path,
|
|
113
|
-
params.amountIn,
|
|
114
|
-
params.minAmountOut,
|
|
115
|
-
params.currencyOut
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// src/errors.ts
|
|
120
|
-
var PafiSDKError = class extends Error {
|
|
121
|
-
constructor(message) {
|
|
122
|
-
super(message);
|
|
123
|
-
this.name = "PafiSDKError";
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
var ConfigurationError = class extends PafiSDKError {
|
|
127
|
-
constructor(message) {
|
|
128
|
-
super(message);
|
|
129
|
-
this.name = "ConfigurationError";
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
var SigningError = class extends PafiSDKError {
|
|
133
|
-
constructor(message) {
|
|
134
|
-
super(message);
|
|
135
|
-
this.name = "SigningError";
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
var SimulationError = class extends PafiSDKError {
|
|
139
|
-
constructor(operation, reason) {
|
|
140
|
-
super(`Simulation failed for ${operation}: ${reason}`);
|
|
141
|
-
this.operation = operation;
|
|
142
|
-
this.reason = reason;
|
|
143
|
-
this.name = "SimulationError";
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
};
|
|
148
|
-
var ApiError = class extends PafiSDKError {
|
|
149
|
-
constructor(message, status) {
|
|
150
|
-
super(message);
|
|
151
|
-
this.status = status;
|
|
152
|
-
this.name = "ApiError";
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
// src/swap/simulate.ts
|
|
158
|
-
async function simulateSwap(client, routerAddress, commands, inputs, deadline, from) {
|
|
159
|
-
try {
|
|
160
|
-
const gasEstimate = await client.estimateContractGas({
|
|
161
|
-
address: routerAddress,
|
|
162
|
-
abi: _chunkIPXARZ6Fcjs.universalRouterAbi,
|
|
163
|
-
functionName: "execute",
|
|
164
|
-
args: [commands, inputs, deadline],
|
|
165
|
-
account: from
|
|
166
|
-
});
|
|
167
|
-
return { success: true, gasEstimate };
|
|
168
|
-
} catch (error) {
|
|
169
|
-
const message = error instanceof Error ? error.message : "Unknown simulation error";
|
|
170
|
-
throw new SimulationError("swap", message);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// src/swap/buildSwapWithGasDeduction.ts
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
// src/userop/batchExecute.ts
|
|
178
|
-
|
|
179
|
-
var BATCH_EXECUTOR_ABI = _viem.parseAbi.call(void 0, [
|
|
180
|
-
"function executeBatch((address target, uint256 value, bytes data)[] calls)"
|
|
181
|
-
]);
|
|
182
|
-
function encodeBatchExecute(operations) {
|
|
183
|
-
if (operations.length === 0) {
|
|
184
|
-
throw new Error("encodeBatchExecute: operations array must not be empty");
|
|
185
|
-
}
|
|
186
|
-
return _viem.encodeFunctionData.call(void 0, {
|
|
187
|
-
abi: BATCH_EXECUTOR_ABI,
|
|
188
|
-
functionName: "executeBatch",
|
|
189
|
-
args: [
|
|
190
|
-
operations.map((op) => ({
|
|
191
|
-
target: op.target,
|
|
192
|
-
value: op.value,
|
|
193
|
-
data: op.data
|
|
194
|
-
}))
|
|
195
|
-
]
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
function decodeBatchExecuteCalls(callData) {
|
|
199
|
-
const { args } = _viem.decodeFunctionData.call(void 0, {
|
|
200
|
-
abi: BATCH_EXECUTOR_ABI,
|
|
201
|
-
data: callData
|
|
202
|
-
});
|
|
203
|
-
return args[0].map((c) => ({
|
|
204
|
-
to: c.target,
|
|
205
|
-
data: c.data,
|
|
206
|
-
value: c.value.toString()
|
|
207
|
-
}));
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// src/userop/buildUserOperation.ts
|
|
211
|
-
var DEFAULT_CALL_GAS_LIMIT = 500000n;
|
|
212
|
-
var DEFAULT_VERIFICATION_GAS_LIMIT = 150000n;
|
|
213
|
-
var DEFAULT_PRE_VERIFICATION_GAS = 50000n;
|
|
214
|
-
function buildPartialUserOperation(params) {
|
|
215
|
-
return {
|
|
216
|
-
sender: params.sender,
|
|
217
|
-
nonce: params.nonce,
|
|
218
|
-
callData: encodeBatchExecute(params.operations),
|
|
219
|
-
callGasLimit: _nullishCoalesce(_optionalChain([params, 'access', _ => _.gasLimits, 'optionalAccess', _2 => _2.callGasLimit]), () => ( DEFAULT_CALL_GAS_LIMIT)),
|
|
220
|
-
verificationGasLimit: _nullishCoalesce(_optionalChain([params, 'access', _3 => _3.gasLimits, 'optionalAccess', _4 => _4.verificationGasLimit]), () => ( DEFAULT_VERIFICATION_GAS_LIMIT)),
|
|
221
|
-
preVerificationGas: _nullishCoalesce(_optionalChain([params, 'access', _5 => _5.gasLimits, 'optionalAccess', _6 => _6.preVerificationGas]), () => ( DEFAULT_PRE_VERIFICATION_GAS)),
|
|
222
|
-
maxFeePerGas: _nullishCoalesce(_optionalChain([params, 'access', _7 => _7.feeOverrides, 'optionalAccess', _8 => _8.maxFeePerGas]), () => ( 0n)),
|
|
223
|
-
maxPriorityFeePerGas: _nullishCoalesce(_optionalChain([params, 'access', _9 => _9.feeOverrides, 'optionalAccess', _10 => _10.maxPriorityFeePerGas]), () => ( 0n))
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
function assembleUserOperation(partial, paymaster, signature) {
|
|
227
|
-
return {
|
|
228
|
-
...partial,
|
|
229
|
-
paymaster: paymaster.paymaster,
|
|
230
|
-
paymasterData: paymaster.paymasterData,
|
|
231
|
-
paymasterVerificationGasLimit: paymaster.paymasterVerificationGasLimit,
|
|
232
|
-
paymasterPostOpGasLimit: paymaster.paymasterPostOpGasLimit,
|
|
233
|
-
signature
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
// src/userop/operations.ts
|
|
238
|
-
|
|
239
|
-
var ERC20_BURNABLE_ABI = _viem.parseAbi.call(void 0, ["function burn(uint256 amount)"]);
|
|
240
|
-
function erc20TransferOp(token, to, amount) {
|
|
241
|
-
return {
|
|
242
|
-
target: token,
|
|
243
|
-
value: 0n,
|
|
244
|
-
data: _viem.encodeFunctionData.call(void 0, {
|
|
245
|
-
abi: _viem.erc20Abi,
|
|
246
|
-
functionName: "transfer",
|
|
247
|
-
args: [to, amount]
|
|
248
|
-
})
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
function erc20ApproveOp(token, spender, amount) {
|
|
252
|
-
return {
|
|
253
|
-
target: token,
|
|
254
|
-
value: 0n,
|
|
255
|
-
data: _viem.encodeFunctionData.call(void 0, {
|
|
256
|
-
abi: _viem.erc20Abi,
|
|
257
|
-
functionName: "approve",
|
|
258
|
-
args: [spender, amount]
|
|
259
|
-
})
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
function erc20BurnOp(token, amount) {
|
|
263
|
-
return {
|
|
264
|
-
target: token,
|
|
265
|
-
value: 0n,
|
|
266
|
-
data: _viem.encodeFunctionData.call(void 0, {
|
|
267
|
-
abi: ERC20_BURNABLE_ABI,
|
|
268
|
-
functionName: "burn",
|
|
269
|
-
args: [amount]
|
|
270
|
-
})
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
function rawCallOp(target, data, value = 0n) {
|
|
274
|
-
return { target, value, data };
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
// src/swap/buildSwapWithGasDeduction.ts
|
|
278
|
-
function buildSwapWithGasDeduction(params) {
|
|
279
|
-
if (params.amountIn <= 0n) {
|
|
280
|
-
throw new Error("buildSwapWithGasDeduction: amountIn must be positive");
|
|
281
|
-
}
|
|
282
|
-
if (params.minAmountOut < 0n) {
|
|
283
|
-
throw new Error(
|
|
284
|
-
"buildSwapWithGasDeduction: minAmountOut must be non-negative"
|
|
285
|
-
);
|
|
286
|
-
}
|
|
287
|
-
if (params.gasFeePt < 0n) {
|
|
288
|
-
throw new Error(
|
|
289
|
-
"buildSwapWithGasDeduction: gasFeePt must be non-negative"
|
|
290
|
-
);
|
|
291
|
-
}
|
|
292
|
-
if (params.swapPath.length === 0) {
|
|
293
|
-
throw new Error(
|
|
294
|
-
"buildSwapWithGasDeduction: swapPath must contain at least one PathKey"
|
|
295
|
-
);
|
|
296
|
-
}
|
|
297
|
-
const { commands, inputs } = buildUniversalRouterExecuteArgs(
|
|
298
|
-
params.pointTokenAddress,
|
|
299
|
-
params.swapPath,
|
|
300
|
-
params.amountIn,
|
|
301
|
-
params.minAmountOut,
|
|
302
|
-
params.outputTokenAddress
|
|
303
|
-
);
|
|
304
|
-
const swapCallData = _viem.encodeFunctionData.call(void 0, {
|
|
305
|
-
abi: _chunkIPXARZ6Fcjs.universalRouterAbi,
|
|
306
|
-
functionName: "execute",
|
|
307
|
-
args: [commands, inputs, params.deadline]
|
|
308
|
-
});
|
|
309
|
-
const permit2ApproveData = buildPermit2ApprovalCalldata(
|
|
310
|
-
params.pointTokenAddress,
|
|
311
|
-
params.universalRouterAddress,
|
|
312
|
-
params.amountIn,
|
|
313
|
-
Number(params.deadline)
|
|
314
|
-
);
|
|
315
|
-
const operations = [
|
|
316
|
-
erc20ApproveOp(
|
|
317
|
-
params.pointTokenAddress,
|
|
318
|
-
_chunkX2JZFK4Ccjs.PERMIT2_ADDRESS,
|
|
319
|
-
params.amountIn
|
|
320
|
-
),
|
|
321
|
-
rawCallOp(_chunkX2JZFK4Ccjs.PERMIT2_ADDRESS, permit2ApproveData),
|
|
322
|
-
rawCallOp(params.universalRouterAddress, swapCallData)
|
|
323
|
-
];
|
|
324
|
-
if (params.gasFeePt > 0n) {
|
|
325
|
-
operations.push(
|
|
326
|
-
erc20TransferOp(
|
|
327
|
-
params.pointTokenAddress,
|
|
328
|
-
params.feeRecipient,
|
|
329
|
-
params.gasFeePt
|
|
330
|
-
)
|
|
331
|
-
);
|
|
332
|
-
}
|
|
333
|
-
return buildPartialUserOperation({
|
|
334
|
-
sender: params.userAddress,
|
|
335
|
-
nonce: params.aaNonce,
|
|
336
|
-
operations,
|
|
337
|
-
gasLimits: {
|
|
338
|
-
callGasLimit: _nullishCoalesce(_optionalChain([params, 'access', _11 => _11.gasLimits, 'optionalAccess', _12 => _12.callGasLimit]), () => ( 700000n)),
|
|
339
|
-
verificationGasLimit: _nullishCoalesce(_optionalChain([params, 'access', _13 => _13.gasLimits, 'optionalAccess', _14 => _14.verificationGasLimit]), () => ( 150000n)),
|
|
340
|
-
preVerificationGas: _nullishCoalesce(_optionalChain([params, 'access', _15 => _15.gasLimits, 'optionalAccess', _16 => _16.preVerificationGas]), () => ( 50000n))
|
|
341
|
-
}
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
exports.PafiSDKError = PafiSDKError; exports.ConfigurationError = ConfigurationError; exports.SigningError = SigningError; exports.SimulationError = SimulationError; exports.ApiError = ApiError; exports.checkAllowance = checkAllowance; exports.buildErc20ApprovalCalldata = buildErc20ApprovalCalldata; exports.buildPermit2ApprovalCalldata = buildPermit2ApprovalCalldata; exports.V4_SWAP = V4_SWAP; exports.SWAP_EXACT_IN = SWAP_EXACT_IN; exports.SETTLE_ALL = SETTLE_ALL; exports.TAKE_ALL = TAKE_ALL; exports.buildV4SwapInput = buildV4SwapInput; exports.buildUniversalRouterExecuteArgs = buildUniversalRouterExecuteArgs; exports.buildSwapFromQuote = buildSwapFromQuote; exports.simulateSwap = simulateSwap; exports.BATCH_EXECUTOR_ABI = BATCH_EXECUTOR_ABI; exports.encodeBatchExecute = encodeBatchExecute; exports.decodeBatchExecuteCalls = decodeBatchExecuteCalls; exports.buildPartialUserOperation = buildPartialUserOperation; exports.assembleUserOperation = assembleUserOperation; exports.erc20TransferOp = erc20TransferOp; exports.erc20ApproveOp = erc20ApproveOp; exports.erc20BurnOp = erc20BurnOp; exports.rawCallOp = rawCallOp; exports.buildSwapWithGasDeduction = buildSwapWithGasDeduction;
|
|
373
|
-
//# sourceMappingURL=chunk-JJ2LGENO.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/phitran/Pacific-Finance/pafi-backend/pafi-sdk/packages/core/dist/chunk-JJ2LGENO.cjs","../src/swap/approval.ts","../src/swap/universalRouter.ts","../src/errors.ts","../src/swap/simulate.ts","../src/swap/buildSwapWithGasDeduction.ts","../src/userop/batchExecute.ts","../src/userop/buildUserOperation.ts","../src/userop/operations.ts"],"names":["encodeFunctionData","erc20Abi"],"mappings":"AAAA;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACA;ACTA,4BAAmC;AAKnC,MAAA,SAAsB,cAAA,CACpB,MAAA,EACA,KAAA,EACA,KAAA,EACA,OAAA,EACiB;AACjB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ACzC,EAAA;AAE+B,EAAA;AACvB,IAAA;AACA,IAAA;AACA,IAAA;AACe,IAAA;AACxB,EAAA;AAEgC,EAAA;AAC9B,IAAA;AACS,MAAA;AACP,MAAA;AACO,MAAA;AACT,IAAA;AAC6C,IAAA;AACJ,IAAA;AAC3C,EAAA;AAE0B,EAAA;AACb,IAAA;AACT,MAAA;AACS,QAAA;AACA,QAAA;AACA,QAAA;AACT,MAAA;AACF,IAAA;AACF,EAAA;AAEiC,EAAA;AAChB,IAAA;AACD,IAAA;AACd,IAAA;AACW,IAAA;AACuC,MAAA;AAE5B,MAAA;AACkB,MAAA;AACxC,IAAA;AACD,EAAA;AACH;ALwKwD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/Users/phitran/Pacific-Finance/pafi-backend/pafi-sdk/packages/core/dist/chunk-JJ2LGENO.cjs","sourcesContent":[null,"import { encodeFunctionData } from \"viem\";\nimport type { Address, Hex, PublicClient } from \"viem\";\nimport { erc20Abi } from \"../abi/erc20\";\nimport { permit2Abi } from \"../abi/permit2\";\n\nexport async function checkAllowance(\n client: PublicClient,\n token: Address,\n owner: Address,\n spender: Address,\n): Promise<bigint> {\n return client.readContract({\n address: token,\n abi: erc20Abi,\n functionName: \"allowance\",\n args: [owner, spender],\n });\n}\n\n/**\n * Encode an ERC-20 approve(spender, amount) call.\n */\nexport function buildErc20ApprovalCalldata(\n spender: Address,\n amount: bigint,\n): Hex {\n return encodeFunctionData({\n abi: erc20Abi,\n functionName: \"approve\",\n args: [spender, amount],\n });\n}\n\n/**\n * Encode a Permit2 approve(token, spender, amount, expiration) call.\n */\nexport function buildPermit2ApprovalCalldata(\n token: Address,\n spender: Address,\n amount: bigint,\n expiration: number,\n): Hex {\n return encodeFunctionData({\n abi: permit2Abi,\n functionName: \"approve\",\n args: [token, spender, amount, expiration],\n });\n}\n","import { encodeAbiParameters, encodePacked } from \"viem\";\nimport type { Address, Hex } from \"viem\";\nimport type { PathKey, QuoteResult } from \"../types\";\n\n// -------------------------------------------------------------------------\n// V4 UniversalRouter command / action constants\n// Reference: https://github.com/Uniswap/v4-periphery/blob/main/src/libraries/Actions.sol\n// -------------------------------------------------------------------------\n\n/** UniversalRouter command byte for V4 swap */\nexport const V4_SWAP = 0x10 as const;\n\n/** V4 actions */\nexport const SWAP_EXACT_IN_SINGLE = 0x06 as const;\nexport const SWAP_EXACT_IN = 0x07 as const;\nexport const SETTLE_ALL = 0x0c as const;\nexport const TAKE_ALL = 0x0f as const;\n\n// -------------------------------------------------------------------------\n// ABI type strings matching Uniswap's V4Planner encoding\n// Reference: https://github.com/Uniswap/sdks/blob/main/sdks/v4-sdk/src/utils/v4Planner.ts\n//\n// IMPORTANT: PathKey.fee is uint256 in the V4 Router ABI (not uint24).\n// -------------------------------------------------------------------------\n\n// PathKey components for V4 Router ABI encoding.\n// IMPORTANT: fee is uint256 in the V4 Router (not uint24 as in PoolKey).\n// Reference: https://github.com/Uniswap/sdks/blob/main/sdks/v4-sdk/src/utils/v4Planner.ts\nconst PATH_KEY_ABI_COMPONENTS = [\n { name: \"intermediateCurrency\", type: \"address\" },\n { name: \"fee\", type: \"uint256\" },\n { name: \"tickSpacing\", type: \"int24\" },\n { name: \"hooks\", type: \"address\" },\n { name: \"hookData\", type: \"bytes\" },\n] as const;\n\nconst EXACT_INPUT_PARAMS_ABI = [\n { name: \"currencyIn\", type: \"address\" },\n {\n name: \"path\",\n type: \"tuple[]\",\n components: PATH_KEY_ABI_COMPONENTS,\n },\n { name: \"amountIn\", type: \"uint128\" },\n { name: \"amountOutMinimum\", type: \"uint128\" },\n] as const;\n\n/**\n * Build the calldata inputs[0] (the V4_SWAP command payload) for\n * UniversalRouter.execute.\n *\n * Actions encoded: SWAP_EXACT_IN → SETTLE_ALL → TAKE_ALL\n *\n * Encoding matches the Uniswap V4 SDK's V4Planner — each action's params\n * are individually ABI-encoded, then wrapped together with the action bytes.\n */\nexport function buildV4SwapInput(\n currencyIn: Address,\n path: PathKey[],\n amountIn: bigint,\n minAmountOut: bigint,\n outputCurrency: Address,\n): Hex {\n const actions = encodePacked(\n [\"uint8\", \"uint8\", \"uint8\"],\n [SWAP_EXACT_IN, SETTLE_ALL, TAKE_ALL],\n );\n\n // Param 0: ExactInputParams — encoded as a single tuple so the CalldataDecoder\n // can locate it via a single offset pointer. fee is uint256 per V4 Router spec.\n const swapParam = encodeAbiParameters(\n [{ name: \"swap\", type: \"tuple\", components: EXACT_INPUT_PARAMS_ABI }],\n [\n {\n currencyIn,\n path: path.map((p) => ({\n intermediateCurrency: p.intermediateCurrency,\n fee: BigInt(p.fee),\n tickSpacing: p.tickSpacing,\n hooks: p.hooks,\n hookData: p.hookData,\n })),\n amountIn,\n amountOutMinimum: minAmountOut,\n },\n ],\n );\n\n // Param 1: SETTLE_ALL { currency, maxAmount }\n const settleParam = encodeAbiParameters(\n [\n { name: \"currency\", type: \"address\" },\n { name: \"maxAmount\", type: \"uint256\" },\n ],\n [currencyIn, amountIn],\n );\n\n // Param 2: TAKE_ALL { currency, minAmount }\n const takeParam = encodeAbiParameters(\n [\n { name: \"currency\", type: \"address\" },\n { name: \"minAmount\", type: \"uint256\" },\n ],\n [outputCurrency, minAmountOut],\n );\n\n return encodeAbiParameters(\n [\n { name: \"actions\", type: \"bytes\" },\n { name: \"params\", type: \"bytes[]\" },\n ],\n [actions, [swapParam, settleParam, takeParam]],\n );\n}\n\n/**\n * Build the full commands + inputs args for UniversalRouter.execute.\n */\nexport function buildUniversalRouterExecuteArgs(\n currencyIn: Address,\n path: PathKey[],\n amountIn: bigint,\n minAmountOut: bigint,\n outputCurrency: Address,\n): { commands: Hex; inputs: Hex[] } {\n const commands = encodePacked([\"uint8\"], [V4_SWAP]);\n const inputs: Hex[] = [\n buildV4SwapInput(currencyIn, path, amountIn, minAmountOut, outputCurrency),\n ];\n return { commands, inputs };\n}\n\n/**\n * Build UniversalRouter execute args from a quote result.\n *\n * Takes the output of `findBestQuote` / `quoteBestRoute` and produces\n * ready-to-use `{ commands, inputs }` for `UniversalRouter.execute`.\n *\n * @param quote - Quote result containing the path\n * @param currencyIn - Input token address\n * @param currencyOut - Output token address\n * @param amountIn - Exact input amount (same value passed to the quoter)\n * @param minAmountOut - Minimum acceptable output (caller applies slippage)\n *\n * @deprecated Since v1.4 — the Issuer App no longer handles swaps.\n * For the new PT→USDT batch call on PAFI Web (Scenario 4 with\n * EIP-7702 gas deduction), use `buildSwapWithGasDeduction()` (v1.5).\n * This helper is kept for legacy v0.2.x consumers; will be removed in v2.0.\n */\nexport function buildSwapFromQuote(params: {\n quote: QuoteResult;\n currencyIn: Address;\n currencyOut: Address;\n amountIn: bigint;\n minAmountOut: bigint;\n}): { commands: Hex; inputs: Hex[] } {\n return buildUniversalRouterExecuteArgs(\n params.currencyIn,\n params.quote.path,\n params.amountIn,\n params.minAmountOut,\n params.currencyOut,\n );\n}\n","export class PafiSDKError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"PafiSDKError\";\n }\n}\n\nexport class ConfigurationError extends PafiSDKError {\n constructor(message: string) {\n super(message);\n this.name = \"ConfigurationError\";\n }\n}\n\nexport class SigningError extends PafiSDKError {\n constructor(message: string) {\n super(message);\n this.name = \"SigningError\";\n }\n}\n\nexport class SimulationError extends PafiSDKError {\n constructor(\n public operation: string,\n public reason: string,\n ) {\n super(`Simulation failed for ${operation}: ${reason}`);\n this.name = \"SimulationError\";\n }\n}\n\nexport class ApiError extends PafiSDKError {\n constructor(\n message: string,\n public status?: number,\n ) {\n super(message);\n this.name = \"ApiError\";\n }\n}\n","import type { Address, Hex, PublicClient } from \"viem\";\nimport { universalRouterAbi } from \"../abi/universalRouter\";\nimport { SimulationError } from \"../errors\";\n\nexport interface SwapSimulationResult {\n success: boolean;\n gasEstimate: bigint;\n}\n\n/**\n * Simulate a UniversalRouter.execute swap call via eth_call (no gas spent).\n *\n * Runs the full V4 swap flow — token transfer via Permit2, swap via\n * PoolManager, output settlement — without submitting a transaction.\n * If the simulation reverts, throws a `SimulationError` with the reason.\n *\n * @param client - viem PublicClient\n * @param routerAddress - UniversalRouter contract address\n * @param commands - Packed command bytes (from buildSwapFromQuote)\n * @param inputs - Encoded inputs per command (from buildSwapFromQuote)\n * @param deadline - Unix timestamp after which the tx expires\n * @param from - Address that will execute the swap\n */\nexport async function simulateSwap(\n client: PublicClient,\n routerAddress: Address,\n commands: Hex,\n inputs: Hex[],\n deadline: bigint,\n from: Address,\n): Promise<SwapSimulationResult> {\n try {\n const gasEstimate = await client.estimateContractGas({\n address: routerAddress,\n abi: universalRouterAbi,\n functionName: \"execute\",\n args: [commands, inputs, deadline],\n account: from,\n });\n\n return { success: true, gasEstimate };\n } catch (error: unknown) {\n const message =\n error instanceof Error ? error.message : \"Unknown simulation error\";\n throw new SimulationError(\"swap\", message);\n }\n}\n","import { encodeFunctionData } from \"viem\";\nimport type { Address, Hex } from \"viem\";\nimport { universalRouterAbi } from \"../abi/universalRouter\";\nimport type { PathKey } from \"../types\";\nimport { buildPartialUserOperation } from \"../userop/buildUserOperation\";\nimport type { PartialUserOperation } from \"../userop/types\";\nimport {\n erc20ApproveOp,\n erc20TransferOp,\n rawCallOp,\n} from \"../userop/operations\";\nimport type { Operation } from \"../userop/types\";\nimport { buildUniversalRouterExecuteArgs } from \"./universalRouter\";\nimport { buildPermit2ApprovalCalldata } from \"./approval\";\nimport { PERMIT2_ADDRESS } from \"../constants\";\n\n/**\n * v1.5 — Scenario 4: Swap PT → USDT on PAFI Web with gas fee\n * deducted in PT from the user's balance.\n *\n * Builds an unsigned `PartialUserOperation` that packages up to four\n * inner calls into a single `BatchExecutor.execute(calls[])`:\n *\n * 1. `PT.approve(Permit2, amountIn)` — grant Permit2 ERC-20 allowance\n * 2. `Permit2.approve(PT, router, amountIn, deadline)` — authorize\n * the UniversalRouter to pull PT via Permit2\n * 3. `UniversalRouter.execute(commands, inputs, deadline)` — V4 swap\n * PT → USDT; user receives ≥ `minAmountOut` USDT\n * 4. `PT.transfer(feeRecipient, gasFeePt)` — pay the operator back\n * for sponsoring the gas, in PT (omitted when `gasFeePt` is 0)\n *\n * The user's wallet must hold `amountIn + gasFeePt` PT before the\n * UserOp runs. All inner calls execute atomically via EIP-7702\n * delegation (`msg.sender = user`), so a reverting swap unwinds\n * the approvals and fee transfer too.\n *\n * ## Fee model\n *\n * The gas fee is a separate `transfer` after the swap — it does NOT\n * come out of the USDT output, because that output goes straight to\n * the user's wallet with no intermediate hook.\n *\n * If the FE wants \"user receives exactly X USDT after gas\":\n * 1. Quote PT→USDT for candidate `amountIn` values\n * 2. Pick an `amountIn` where `minAmountOut ≈ X`\n * 3. Separately compute `gasFeePt` from the operator's rate\n * 4. Ensure user's PT balance ≥ `amountIn + gasFeePt`\n *\n * ## Order of operations\n *\n * Fee transfer is last so a reverting swap also refunds the fee\n * (atomic batch revert semantics).\n */\nexport interface BuildSwapWithGasDeductionParams {\n /** User's EOA (with EIP-7702 delegation to BatchExecutor). */\n userAddress: Address;\n /** ERC-4337 account nonce — fetched from EntryPoint by the caller. */\n aaNonce: bigint;\n\n /** PT token address being swapped. */\n pointTokenAddress: Address;\n /** Destination currency (typically USDT). */\n outputTokenAddress: Address;\n /** UniversalRouter contract address (chain-specific). */\n universalRouterAddress: Address;\n\n /** PT units to swap. User's balance must be ≥ `amountIn + gasFeePt`. */\n amountIn: bigint;\n /**\n * Minimum USDT to accept out of the swap. Caller applies slippage\n * (typically ~0.5-1%) against a fresh quote. Sub-minimum swap reverts.\n */\n minAmountOut: bigint;\n\n /** V4 pool path for the swap. Single-hop = 1 PathKey. */\n swapPath: PathKey[];\n /** Unix seconds. After this, the router rejects the swap. */\n deadline: bigint;\n\n /** PT amount transferred to `feeRecipient` as gas fee recovery. */\n gasFeePt: bigint;\n /** Where the gas fee lands — typically the operator or fee collector. */\n feeRecipient: Address;\n\n /** Override ERC-4337 gas estimates. Defaults are conservative; tune down for cheaper UserOps. */\n gasLimits?: {\n callGasLimit?: bigint;\n verificationGasLimit?: bigint;\n preVerificationGas?: bigint;\n };\n}\n\n/**\n * Build an unsigned UserOp for Scenario 4. Returns a\n * `PartialUserOperation` — caller attaches paymaster sponsorship (via\n * `POST /api/paymaster/sponsor`), adds the user's UserOp-hash\n * signature, and submits to the Bundler.\n *\n * @throws when `amountIn` or `gasFeePt` is not positive, or when\n * `swapPath` is empty (at least one PathKey required).\n */\nexport function buildSwapWithGasDeduction(\n params: BuildSwapWithGasDeductionParams,\n): PartialUserOperation {\n if (params.amountIn <= 0n) {\n throw new Error(\"buildSwapWithGasDeduction: amountIn must be positive\");\n }\n if (params.minAmountOut < 0n) {\n throw new Error(\n \"buildSwapWithGasDeduction: minAmountOut must be non-negative\",\n );\n }\n if (params.gasFeePt < 0n) {\n throw new Error(\n \"buildSwapWithGasDeduction: gasFeePt must be non-negative\",\n );\n }\n if (params.swapPath.length === 0) {\n throw new Error(\n \"buildSwapWithGasDeduction: swapPath must contain at least one PathKey\",\n );\n }\n\n const { commands, inputs } = buildUniversalRouterExecuteArgs(\n params.pointTokenAddress,\n params.swapPath,\n params.amountIn,\n params.minAmountOut,\n params.outputTokenAddress,\n );\n\n const swapCallData: Hex = encodeFunctionData({\n abi: universalRouterAbi,\n functionName: \"execute\",\n args: [commands, inputs, params.deadline],\n });\n\n const permit2ApproveData: Hex = buildPermit2ApprovalCalldata(\n params.pointTokenAddress,\n params.universalRouterAddress,\n params.amountIn,\n Number(params.deadline),\n );\n\n const operations: Operation[] = [\n erc20ApproveOp(\n params.pointTokenAddress,\n PERMIT2_ADDRESS,\n params.amountIn,\n ),\n rawCallOp(PERMIT2_ADDRESS, permit2ApproveData),\n rawCallOp(params.universalRouterAddress, swapCallData),\n ];\n\n if (params.gasFeePt > 0n) {\n operations.push(\n erc20TransferOp(\n params.pointTokenAddress,\n params.feeRecipient,\n params.gasFeePt,\n ),\n );\n }\n\n return buildPartialUserOperation({\n sender: params.userAddress,\n nonce: params.aaNonce,\n operations,\n gasLimits: {\n callGasLimit: params.gasLimits?.callGasLimit ?? 700_000n,\n verificationGasLimit:\n params.gasLimits?.verificationGasLimit ?? 150_000n,\n preVerificationGas: params.gasLimits?.preVerificationGas ?? 50_000n,\n },\n });\n}\n","import { decodeFunctionData, encodeFunctionData, parseAbi } from \"viem\";\nimport type { Address, Hex } from \"viem\";\nimport type { Operation } from \"./types\";\n\n/**\n * Standard BatchExecutor ABI — a contract that takes an array of calls\n * and invokes each one in sequence, reverting all if any fail.\n *\n * Function name is `executeBatch` (selector `0x34fcd5be`) to match\n * Pimlico's `Simple7702Account` and Coinbase Smart Wallet v2 — both\n * EIP-7702 delegate impls expose `executeBatch(Call[])`, not `execute`.\n * The shorter `execute(Call[])` (selector `0x3f707e6b`) only exists on\n * legacy/standalone batch executor contracts; calling it on a 7702\n * delegated EOA falls through to the fallback function and reverts\n * with \"account: not from EntryPoint\" (AA23).\n */\nexport const BATCH_EXECUTOR_ABI = parseAbi([\n \"function executeBatch((address target, uint256 value, bytes data)[] calls)\",\n]);\n\n/**\n * Encode a batch of operations into calldata for `BatchExecutor.execute()`.\n * The resulting calldata goes into `UserOperation.callData`.\n *\n * When the EOA has an EIP-7702 delegation to a BatchExecutor, calling\n * this calldata against the EOA runs all operations with\n * `msg.sender = EOA` for each inner call.\n *\n * @param operations batch of calls, in execution order\n * @returns calldata bytes for `execute((address,uint256,bytes)[])`\n */\nexport function encodeBatchExecute(operations: Operation[]): Hex {\n if (operations.length === 0) {\n throw new Error(\"encodeBatchExecute: operations array must not be empty\");\n }\n return encodeFunctionData({\n abi: BATCH_EXECUTOR_ABI,\n functionName: \"executeBatch\",\n args: [\n operations.map((op) => ({\n target: op.target,\n value: op.value,\n data: op.data,\n })),\n ],\n });\n}\n\n/**\n * Decode `BatchExecutor.execute(calls[])` callData back into individual\n * `{ to, data, value }` objects.\n *\n * Used by issuer backends to convert a `PartialUserOperation.callData`\n * into the `calls[]` array returned to web/FE clients (which submit via\n * `permissionless.sendTransaction({ calls })`).\n */\nexport function decodeBatchExecuteCalls(\n callData: Hex,\n): Array<{ to: string; data: string; value: string }> {\n const { args } = decodeFunctionData({\n abi: BATCH_EXECUTOR_ABI,\n data: callData,\n });\n return (\n args[0] as ReadonlyArray<{ target: Address; value: bigint; data: Hex }>\n ).map((c) => ({\n to: c.target,\n data: c.data,\n value: c.value.toString(),\n }));\n}\n","import type { Address } from \"viem\";\nimport type { Operation, PartialUserOperation, UserOperation } from \"./types\";\nimport { encodeBatchExecute } from \"./batchExecute\";\n\n/**\n * Default gas limits — rough upper bounds for a 2-op batch on Base.\n * Bundler re-estimates before submission, so these are only used when\n * the caller doesn't supply their own.\n */\nconst DEFAULT_CALL_GAS_LIMIT = 500_000n;\nconst DEFAULT_VERIFICATION_GAS_LIMIT = 150_000n;\nconst DEFAULT_PRE_VERIFICATION_GAS = 50_000n;\n\nexport interface BuildPartialUserOpParams {\n /** User's EOA (with EIP-7702 delegation). */\n sender: Address;\n /** Batch of operations — encoded into callData via `encodeBatchExecute`. */\n operations: Operation[];\n /** EntryPoint nonce for this sender. Caller fetches from the EntryPoint contract. */\n nonce: bigint;\n /** Optional gas overrides; bundler re-estimates before submission. */\n gasLimits?: {\n callGasLimit?: bigint;\n verificationGasLimit?: bigint;\n preVerificationGas?: bigint;\n };\n /** Optional fee overrides; bundler usually fills these. */\n feeOverrides?: {\n maxFeePerGas?: bigint;\n maxPriorityFeePerGas?: bigint;\n };\n}\n\n/**\n * Build a partial ERC-4337 UserOperation from a batch of operations.\n * Paymaster fields and signature are populated later:\n * 1. Call `PafiBackendClient.requestSponsorship()` → get paymaster fields\n * 2. Compute userOpHash and have the user sign it (via Privy)\n * 3. Attach `signature` → submit to bundler\n *\n * This function is a pure struct builder — no network calls.\n */\nexport function buildPartialUserOperation(\n params: BuildPartialUserOpParams,\n): PartialUserOperation {\n return {\n sender: params.sender,\n nonce: params.nonce,\n callData: encodeBatchExecute(params.operations),\n callGasLimit: params.gasLimits?.callGasLimit ?? DEFAULT_CALL_GAS_LIMIT,\n verificationGasLimit:\n params.gasLimits?.verificationGasLimit ??\n DEFAULT_VERIFICATION_GAS_LIMIT,\n preVerificationGas:\n params.gasLimits?.preVerificationGas ?? DEFAULT_PRE_VERIFICATION_GAS,\n maxFeePerGas: params.feeOverrides?.maxFeePerGas ?? 0n,\n maxPriorityFeePerGas: params.feeOverrides?.maxPriorityFeePerGas ?? 0n,\n };\n}\n\n/**\n * Assemble a full UserOperation once paymaster fields + signature are\n * known. Used after `PafiBackendClient.requestSponsorship()` and user\n * signing complete.\n */\nexport function assembleUserOperation(\n partial: PartialUserOperation,\n paymaster: {\n paymaster: Address;\n paymasterData: `0x${string}`;\n paymasterVerificationGasLimit: bigint;\n paymasterPostOpGasLimit: bigint;\n },\n signature: `0x${string}`,\n): UserOperation {\n return {\n ...partial,\n paymaster: paymaster.paymaster,\n paymasterData: paymaster.paymasterData,\n paymasterVerificationGasLimit: paymaster.paymasterVerificationGasLimit,\n paymasterPostOpGasLimit: paymaster.paymasterPostOpGasLimit,\n signature,\n };\n}\n","import { encodeFunctionData, erc20Abi, parseAbi } from \"viem\";\nimport type { Address } from \"viem\";\nimport type { Operation } from \"./types\";\n\n/**\n * ERC20Burnable extension — `burn(uint256 amount)` burns from msg.sender.\n * The EOA (via EIP-7702 delegation) is the `msg.sender` when a batch\n * runs — so this burns the user's balance without any role check.\n */\nconst ERC20_BURNABLE_ABI = parseAbi([\"function burn(uint256 amount)\"]);\n\n/**\n * Build an ERC-20 `transfer(to, amount)` operation. Used inside a batch\n * to move fee tokens from the user to the fee recipient atomically with\n * the main action.\n */\nexport function erc20TransferOp(\n token: Address,\n to: Address,\n amount: bigint,\n): Operation {\n return {\n target: token,\n value: 0n,\n data: encodeFunctionData({\n abi: erc20Abi,\n functionName: \"transfer\",\n args: [to, amount],\n }),\n };\n}\n\n/**\n * Build an ERC-20 `approve(spender, amount)` operation. Used inside a\n * batch before a swap / deposit call so the AMM / protocol can pull\n * tokens from the user.\n */\nexport function erc20ApproveOp(\n token: Address,\n spender: Address,\n amount: bigint,\n): Operation {\n return {\n target: token,\n value: 0n,\n data: encodeFunctionData({\n abi: erc20Abi,\n functionName: \"approve\",\n args: [spender, amount],\n }),\n };\n}\n\n/**\n * Build an ERC-20 `burn(amount)` operation (OpenZeppelin ERC20Burnable\n * extension). Burns from `msg.sender`, which — via EIP-7702 — is the\n * user's EOA.\n *\n * Requires the PointToken contract to expose a public `burn(uint256)`\n * without a role check. See\n * [SDK_V1.4_TASKS.md §11 — PointToken.burn callable via batch].\n */\nexport function erc20BurnOp(token: Address, amount: bigint): Operation {\n return {\n target: token,\n value: 0n,\n data: encodeFunctionData({\n abi: ERC20_BURNABLE_ABI,\n functionName: \"burn\",\n args: [amount],\n }),\n };\n}\n\n/**\n * Build a raw call operation with caller-supplied calldata. Useful for\n * non-ERC-20 contracts (PoolManager.swap, PerpDEX.deposit, Relayer.mint)\n * where the encoding is specific to that protocol.\n */\nexport function rawCallOp(\n target: Address,\n data: `0x${string}`,\n value: bigint = 0n,\n): Operation {\n return { target, value, data };\n}\n"]}
|
package/dist/chunk-KFWZRL7I.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
// src/abi/v4Quoter.ts
|
|
2
|
-
var poolKeyComponents = [
|
|
3
|
-
{ name: "currency0", type: "address" },
|
|
4
|
-
{ name: "currency1", type: "address" },
|
|
5
|
-
{ name: "fee", type: "uint24" },
|
|
6
|
-
{ name: "tickSpacing", type: "int24" },
|
|
7
|
-
{ name: "hooks", type: "address" }
|
|
8
|
-
];
|
|
9
|
-
var pathKeyComponents = [
|
|
10
|
-
{ name: "intermediateCurrency", type: "address" },
|
|
11
|
-
{ name: "fee", type: "uint24" },
|
|
12
|
-
{ name: "tickSpacing", type: "int24" },
|
|
13
|
-
{ name: "hooks", type: "address" },
|
|
14
|
-
{ name: "hookData", type: "bytes" }
|
|
15
|
-
];
|
|
16
|
-
var v4QuoterAbi = [
|
|
17
|
-
// quoteExactInputSingle — single-hop quote
|
|
18
|
-
{
|
|
19
|
-
type: "function",
|
|
20
|
-
name: "quoteExactInputSingle",
|
|
21
|
-
stateMutability: "nonpayable",
|
|
22
|
-
inputs: [
|
|
23
|
-
{
|
|
24
|
-
name: "params",
|
|
25
|
-
type: "tuple",
|
|
26
|
-
components: [
|
|
27
|
-
{ name: "poolKey", type: "tuple", components: poolKeyComponents },
|
|
28
|
-
{ name: "zeroForOne", type: "bool" },
|
|
29
|
-
{ name: "exactAmount", type: "uint128" },
|
|
30
|
-
{ name: "hookData", type: "bytes" }
|
|
31
|
-
]
|
|
32
|
-
}
|
|
33
|
-
],
|
|
34
|
-
outputs: [
|
|
35
|
-
{ name: "amountOut", type: "uint256" },
|
|
36
|
-
{ name: "gasEstimate", type: "uint256" }
|
|
37
|
-
]
|
|
38
|
-
},
|
|
39
|
-
// quoteExactInput — multi-hop quote
|
|
40
|
-
{
|
|
41
|
-
type: "function",
|
|
42
|
-
name: "quoteExactInput",
|
|
43
|
-
stateMutability: "nonpayable",
|
|
44
|
-
inputs: [
|
|
45
|
-
{
|
|
46
|
-
name: "params",
|
|
47
|
-
type: "tuple",
|
|
48
|
-
components: [
|
|
49
|
-
{ name: "exactCurrency", type: "address" },
|
|
50
|
-
{ name: "path", type: "tuple[]", components: pathKeyComponents },
|
|
51
|
-
{ name: "exactAmount", type: "uint128" }
|
|
52
|
-
]
|
|
53
|
-
}
|
|
54
|
-
],
|
|
55
|
-
outputs: [
|
|
56
|
-
{ name: "amountOut", type: "uint256" },
|
|
57
|
-
{ name: "gasEstimate", type: "uint256" }
|
|
58
|
-
]
|
|
59
|
-
}
|
|
60
|
-
];
|
|
61
|
-
|
|
62
|
-
export {
|
|
63
|
-
v4QuoterAbi
|
|
64
|
-
};
|
|
65
|
-
//# sourceMappingURL=chunk-KFWZRL7I.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/abi/v4Quoter.ts"],"sourcesContent":["// IV4Quoter — Uniswap V4 Quoter interface\n\nconst poolKeyComponents = [\n { name: \"currency0\", type: \"address\" },\n { name: \"currency1\", type: \"address\" },\n { name: \"fee\", type: \"uint24\" },\n { name: \"tickSpacing\", type: \"int24\" },\n { name: \"hooks\", type: \"address\" },\n] as const;\n\nconst pathKeyComponents = [\n { name: \"intermediateCurrency\", type: \"address\" },\n { name: \"fee\", type: \"uint24\" },\n { name: \"tickSpacing\", type: \"int24\" },\n { name: \"hooks\", type: \"address\" },\n { name: \"hookData\", type: \"bytes\" },\n] as const;\n\nexport const v4QuoterAbi = [\n // quoteExactInputSingle — single-hop quote\n {\n type: \"function\",\n name: \"quoteExactInputSingle\",\n stateMutability: \"nonpayable\",\n inputs: [\n {\n name: \"params\",\n type: \"tuple\",\n components: [\n { name: \"poolKey\", type: \"tuple\", components: poolKeyComponents },\n { name: \"zeroForOne\", type: \"bool\" },\n { name: \"exactAmount\", type: \"uint128\" },\n { name: \"hookData\", type: \"bytes\" },\n ],\n },\n ],\n outputs: [\n { name: \"amountOut\", type: \"uint256\" },\n { name: \"gasEstimate\", type: \"uint256\" },\n ],\n },\n // quoteExactInput — multi-hop quote\n {\n type: \"function\",\n name: \"quoteExactInput\",\n stateMutability: \"nonpayable\",\n inputs: [\n {\n name: \"params\",\n type: \"tuple\",\n components: [\n { name: \"exactCurrency\", type: \"address\" },\n { name: \"path\", type: \"tuple[]\", components: pathKeyComponents },\n { name: \"exactAmount\", type: \"uint128\" },\n ],\n },\n ],\n outputs: [\n { name: \"amountOut\", type: \"uint256\" },\n { name: \"gasEstimate\", type: \"uint256\" },\n ],\n },\n] as const;\n"],"mappings":";AAEA,IAAM,oBAAoB;AAAA,EACxB,EAAE,MAAM,aAAa,MAAM,UAAU;AAAA,EACrC,EAAE,MAAM,aAAa,MAAM,UAAU;AAAA,EACrC,EAAE,MAAM,OAAO,MAAM,SAAS;AAAA,EAC9B,EAAE,MAAM,eAAe,MAAM,QAAQ;AAAA,EACrC,EAAE,MAAM,SAAS,MAAM,UAAU;AACn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k-L5UHQQVC.cjs
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
-
|
|
3
|
-
var _chunkCL3QSI4Ocjs = require('./chunk-CL3QSI4O.cjs');
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var _chunkX2JZFK4Ccjs = require('./chunk-X2JZFK4C.cjs');
|
|
9
|
-
|
|
10
|
-
// src/quoting/routes.ts
|
|
11
|
-
var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
12
|
-
function combineRoutes(chainId, pointTokenAddress) {
|
|
13
|
-
const commonPools = _nullishCoalesce(_chunkX2JZFK4Ccjs.COMMON_POOLS[chainId], () => ( []));
|
|
14
|
-
const pointPools = _nullishCoalesce(_optionalChain([_chunkX2JZFK4Ccjs.POINT_TOKEN_POOLS, 'access', _ => _[chainId], 'optionalAccess', _2 => _2[pointTokenAddress]]), () => ( []));
|
|
15
|
-
return [...pointPools, ...commonPools];
|
|
16
|
-
}
|
|
17
|
-
function buildAllPaths(pools, tokenIn, tokenOut, maxHops = 3) {
|
|
18
|
-
const results = [];
|
|
19
|
-
function dfs(currentToken, currentPath, usedPoolIndices) {
|
|
20
|
-
if (currentPath.length > maxHops) return;
|
|
21
|
-
if (currentPath.length > 0 && currentToken.toLowerCase() === tokenOut.toLowerCase()) {
|
|
22
|
-
results.push([...currentPath]);
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
for (let i = 0; i < pools.length; i++) {
|
|
26
|
-
if (usedPoolIndices.has(i)) continue;
|
|
27
|
-
const pool = pools[i];
|
|
28
|
-
const c0 = pool.currency0.toLowerCase();
|
|
29
|
-
const c1 = pool.currency1.toLowerCase();
|
|
30
|
-
const curr = currentToken.toLowerCase();
|
|
31
|
-
let nextToken = null;
|
|
32
|
-
if (curr === c0) {
|
|
33
|
-
nextToken = pool.currency1;
|
|
34
|
-
} else if (curr === c1) {
|
|
35
|
-
nextToken = pool.currency0;
|
|
36
|
-
}
|
|
37
|
-
if (!nextToken) continue;
|
|
38
|
-
const hop = {
|
|
39
|
-
intermediateCurrency: nextToken,
|
|
40
|
-
fee: pool.fee,
|
|
41
|
-
tickSpacing: pool.tickSpacing,
|
|
42
|
-
hooks: _nullishCoalesce(pool.hooks, () => ( ZERO_ADDRESS)),
|
|
43
|
-
hookData: "0x"
|
|
44
|
-
};
|
|
45
|
-
usedPoolIndices.add(i);
|
|
46
|
-
currentPath.push(hop);
|
|
47
|
-
dfs(nextToken, currentPath, usedPoolIndices);
|
|
48
|
-
currentPath.pop();
|
|
49
|
-
usedPoolIndices.delete(i);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
dfs(tokenIn, [], /* @__PURE__ */ new Set());
|
|
53
|
-
return results;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// src/quoting/quote.ts
|
|
57
|
-
async function quoteExactInput(client, quoterAddress, exactCurrency, path, exactAmount) {
|
|
58
|
-
const [amountOut, gasEstimate] = await client.readContract({
|
|
59
|
-
address: quoterAddress,
|
|
60
|
-
abi: _chunkCL3QSI4Ocjs.v4QuoterAbi,
|
|
61
|
-
functionName: "quoteExactInput",
|
|
62
|
-
args: [{ exactCurrency, path, exactAmount: BigInt(exactAmount) }]
|
|
63
|
-
});
|
|
64
|
-
return { amountOut, gasEstimate, path };
|
|
65
|
-
}
|
|
66
|
-
async function quoteExactInputSingle(client, quoterAddress, poolKey, zeroForOne, exactAmount, hookData) {
|
|
67
|
-
const [amountOut, gasEstimate] = await client.readContract({
|
|
68
|
-
address: quoterAddress,
|
|
69
|
-
abi: _chunkCL3QSI4Ocjs.v4QuoterAbi,
|
|
70
|
-
functionName: "quoteExactInputSingle",
|
|
71
|
-
args: [
|
|
72
|
-
{
|
|
73
|
-
poolKey,
|
|
74
|
-
zeroForOne,
|
|
75
|
-
exactAmount: BigInt(exactAmount),
|
|
76
|
-
hookData
|
|
77
|
-
}
|
|
78
|
-
]
|
|
79
|
-
});
|
|
80
|
-
return { amountOut, gasEstimate };
|
|
81
|
-
}
|
|
82
|
-
async function quoteBestRoute(client, quoterAddress, exactCurrency, routes, exactAmount) {
|
|
83
|
-
const results = await client.multicall({
|
|
84
|
-
contracts: routes.map((path) => ({
|
|
85
|
-
address: quoterAddress,
|
|
86
|
-
abi: _chunkCL3QSI4Ocjs.v4QuoterAbi,
|
|
87
|
-
functionName: "quoteExactInput",
|
|
88
|
-
args: [
|
|
89
|
-
{
|
|
90
|
-
exactCurrency,
|
|
91
|
-
path,
|
|
92
|
-
exactAmount: BigInt(exactAmount)
|
|
93
|
-
}
|
|
94
|
-
]
|
|
95
|
-
})),
|
|
96
|
-
allowFailure: true
|
|
97
|
-
});
|
|
98
|
-
const allRoutes = [];
|
|
99
|
-
for (let i = 0; i < results.length; i++) {
|
|
100
|
-
const r = results[i];
|
|
101
|
-
if (r.status === "success") {
|
|
102
|
-
const [amountOut, gasEstimate] = r.result;
|
|
103
|
-
allRoutes.push({ amountOut, gasEstimate, path: routes[i] });
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
if (allRoutes.length === 0) {
|
|
107
|
-
throw new Error("No valid routes found");
|
|
108
|
-
}
|
|
109
|
-
const bestRoute = allRoutes.reduce(
|
|
110
|
-
(best, current) => current.amountOut > best.amountOut ? current : best
|
|
111
|
-
);
|
|
112
|
-
return { bestRoute, allRoutes };
|
|
113
|
-
}
|
|
114
|
-
async function findBestQuote(client, chainId, tokenIn, tokenOut, exactAmount, pools = [], quoterAddress, maxHops = 3) {
|
|
115
|
-
const quoter = _nullishCoalesce(quoterAddress, () => ( _chunkX2JZFK4Ccjs.V4_QUOTER_ADDRESSES[chainId]));
|
|
116
|
-
if (!quoter) {
|
|
117
|
-
throw new Error(`No V4 Quoter address configured for chain ${chainId}`);
|
|
118
|
-
}
|
|
119
|
-
const commonPools = _nullishCoalesce(_chunkX2JZFK4Ccjs.COMMON_POOLS[chainId], () => ( []));
|
|
120
|
-
const allPools = [...pools, ...commonPools];
|
|
121
|
-
const paths = buildAllPaths(allPools, tokenIn, tokenOut, maxHops);
|
|
122
|
-
if (paths.length === 0) {
|
|
123
|
-
throw new Error(`No paths found from ${tokenIn} to ${tokenOut}`);
|
|
124
|
-
}
|
|
125
|
-
return quoteBestRoute(client, quoter, tokenIn, paths, exactAmount);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
exports.combineRoutes = combineRoutes; exports.buildAllPaths = buildAllPaths; exports.quoteExactInput = quoteExactInput; exports.quoteExactInputSingle = quoteExactInputSingle; exports.quoteBestRoute = quoteBestRoute; exports.findBestQuote = findBestQuote;
|
|
136
|
-
//# sourceMappingURL=chunk-L5UHQQVC.cjs.map
|