Skip to content

Commit 373f95b

Browse files
committed
batch permit decode in calldata
1 parent 6c91122 commit 373f95b

File tree

5 files changed

+46
-44
lines changed

5 files changed

+46
-44
lines changed

contracts/base/Dispatcher.sol

+4-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,10 @@ abstract contract Dispatcher is Payments, V2SwapRouter, V3SwapRouter, V3ToV4Migr
8686
}
8787
permit2TransferFrom(token, _msgSender(), map(recipient), amount);
8888
} else if (command == Commands.PERMIT2_PERMIT_BATCH) {
89-
(IAllowanceTransfer.PermitBatch memory permitBatch,) =
90-
abi.decode(inputs, (IAllowanceTransfer.PermitBatch, bytes));
89+
IAllowanceTransfer.PermitBatch calldata permitBatch;
90+
assembly {
91+
permitBatch := add(inputs.offset, calldataload(inputs.offset))
92+
}
9193
bytes calldata data = inputs.toBytes(1);
9294
PERMIT2.permit(_msgSender(), permitBatch, data);
9395
} else if (command == Commands.SWEEP) {

test/integration-tests/gas-tests/__snapshots__/Payments.gas.test.ts.snap

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@
33
exports[`Payments Gas Tests Individual Command Tests gas: SWEEP with ERC20 1`] = `
44
Object {
55
"calldataByteLength": 356,
6-
"gasUsed": 37013,
6+
"gasUsed": 36960,
77
}
88
`;
99

1010
exports[`Payments Gas Tests Individual Command Tests gas: SWEEP_WITH_FEE 1`] = `
1111
Object {
1212
"calldataByteLength": 516,
13-
"gasUsed": 65690,
13+
"gasUsed": 65584,
1414
}
1515
`;
1616

1717
exports[`Payments Gas Tests Individual Command Tests gas: TRANSFER with ERC20 1`] = `
1818
Object {
1919
"calldataByteLength": 356,
20-
"gasUsed": 36038,
20+
"gasUsed": 35985,
2121
}
2222
`;
2323

2424
exports[`Payments Gas Tests Individual Command Tests gas: TRANSFER with ETH 1`] = `
2525
Object {
2626
"calldataByteLength": 356,
27-
"gasUsed": 31609,
27+
"gasUsed": 31556,
2828
}
2929
`;
3030

@@ -38,7 +38,7 @@ Object {
3838
exports[`Payments Gas Tests Individual Command Tests gas: UNWRAP_WETH_WITH_FEE 1`] = `
3939
Object {
4040
"calldataByteLength": 644,
41-
"gasUsed": 50905,
41+
"gasUsed": 50799,
4242
}
4343
`;
4444

test/integration-tests/gas-tests/__snapshots__/Uniswap.gas.test.ts.snap

+26-26
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,49 @@
33
exports[`Uniswap Gas Tests Mixing V2 and V3 with Universal Router. Batch reverts gas: 2 sub-plans, both fail but the transaction succeeds 1`] = `
44
Object {
55
"calldataByteLength": 1764,
6-
"gasUsed": 269421,
6+
"gasUsed": 269286,
77
}
88
`;
99

1010
exports[`Uniswap Gas Tests Mixing V2 and V3 with Universal Router. Batch reverts gas: 2 sub-plans, neither fails 1`] = `
1111
Object {
1212
"calldataByteLength": 1764,
13-
"gasUsed": 245148,
13+
"gasUsed": 245013,
1414
}
1515
`;
1616

1717
exports[`Uniswap Gas Tests Mixing V2 and V3 with Universal Router. Batch reverts gas: 2 sub-plans, second sub plan fails 1`] = `
1818
Object {
1919
"calldataByteLength": 1764,
20-
"gasUsed": 245148,
20+
"gasUsed": 245013,
2121
}
2222
`;
2323

2424
exports[`Uniswap Gas Tests Mixing V2 and V3 with Universal Router. Batch reverts gas: 2 sub-plans, the first fails 1`] = `
2525
Object {
2626
"calldataByteLength": 1764,
27-
"gasUsed": 269421,
27+
"gasUsed": 269286,
2828
}
2929
`;
3030

3131
exports[`Uniswap Gas Tests Mixing V2 and V3 with Universal Router. Interleaving routes gas: V2, then V3 1`] = `
3232
Object {
3333
"calldataByteLength": 836,
34-
"gasUsed": 189470,
34+
"gasUsed": 189429,
3535
}
3636
`;
3737

3838
exports[`Uniswap Gas Tests Mixing V2 and V3 with Universal Router. Interleaving routes gas: V3, then V2 1`] = `
3939
Object {
4040
"calldataByteLength": 836,
41-
"gasUsed": 177054,
41+
"gasUsed": 177013,
4242
}
4343
`;
4444

4545
exports[`Uniswap Gas Tests Mixing V2 and V3 with Universal Router. Split routes gas: ERC20 --> ERC20 split V2 and V2 different routes, different input tokens, each two hop, with batch permit 1`] = `
4646
Object {
4747
"calldataByteLength": 1540,
48-
"gasUsed": 298488,
48+
"gasUsed": 297045,
4949
}
5050
`;
5151

@@ -59,7 +59,7 @@ Object {
5959
exports[`Uniswap Gas Tests Mixing V2 and V3 with Universal Router. Split routes gas: ERC20 --> ERC20 split V2 and V2 different routes, each two hop, with explicit permit transfer from batch 1`] = `
6060
Object {
6161
"calldataByteLength": 1284,
62-
"gasUsed": 309785,
62+
"gasUsed": 309749,
6363
}
6464
`;
6565

@@ -73,35 +73,35 @@ Object {
7373
exports[`Uniswap Gas Tests Mixing V2 and V3 with Universal Router. Split routes gas: ERC20 --> ERC20 split V2 and V3, one hop 1`] = `
7474
Object {
7575
"calldataByteLength": 996,
76-
"gasUsed": 176845,
76+
"gasUsed": 176751,
7777
}
7878
`;
7979

8080
exports[`Uniswap Gas Tests Mixing V2 and V3 with Universal Router. Split routes gas: ERC20 --> ERC20 split V2 and V3, one hop, ADDRESS_THIS flag 1`] = `
8181
Object {
8282
"calldataByteLength": 996,
83-
"gasUsed": 176620,
83+
"gasUsed": 176526,
8484
}
8585
`;
8686

8787
exports[`Uniswap Gas Tests Mixing V2 and V3 with Universal Router. Split routes gas: ERC20 --> ETH split V2 and V3, exactOut, one hop 1`] = `
8888
Object {
8989
"calldataByteLength": 964,
90-
"gasUsed": 194645,
90+
"gasUsed": 194604,
9191
}
9292
`;
9393

9494
exports[`Uniswap Gas Tests Mixing V2 and V3 with Universal Router. Split routes gas: ERC20 --> ETH split V2 and V3, one hop 1`] = `
9595
Object {
9696
"calldataByteLength": 964,
97-
"gasUsed": 184716,
97+
"gasUsed": 184675,
9898
}
9999
`;
100100

101101
exports[`Uniswap Gas Tests Mixing V2 and V3 with Universal Router. Split routes gas: ETH --> ERC20 split V2 and V3, one hop 1`] = `
102102
Object {
103103
"calldataByteLength": 1124,
104-
"gasUsed": 191723,
104+
"gasUsed": 191629,
105105
}
106106
`;
107107

@@ -143,7 +143,7 @@ Object {
143143
exports[`Uniswap Gas Tests Trade on UniswapV2 with Universal Router. ERC20 --> ERC20 gas: exactIn trade, where an output fee is taken 1`] = `
144144
Object {
145145
"calldataByteLength": 836,
146-
"gasUsed": 126565,
146+
"gasUsed": 126459,
147147
}
148148
`;
149149

@@ -213,14 +213,14 @@ Object {
213213
exports[`Uniswap Gas Tests Trade on UniswapV2 with Universal Router. ERC20 --> ETH gas: exactOut, one trade, one hop 1`] = `
214214
Object {
215215
"calldataByteLength": 804,
216-
"gasUsed": 128329,
216+
"gasUsed": 128276,
217217
}
218218
`;
219219

220220
exports[`Uniswap Gas Tests Trade on UniswapV2 with Universal Router. ERC20 --> ETH gas: exactOut, with ETH fee 1`] = `
221221
Object {
222222
"calldataByteLength": 964,
223-
"gasUsed": 136301,
223+
"gasUsed": 136195,
224224
}
225225
`;
226226

@@ -283,69 +283,69 @@ Object {
283283
exports[`Uniswap Gas Tests Trade on UniswapV3 with Universal Router. ERC20 --> ERC20 gas: exactIn, one trade, one hop 1`] = `
284284
Object {
285285
"calldataByteLength": 516,
286-
"gasUsed": 105541,
286+
"gasUsed": 105500,
287287
}
288288
`;
289289

290290
exports[`Uniswap Gas Tests Trade on UniswapV3 with Universal Router. ERC20 --> ERC20 gas: exactIn, one trade, three hops 1`] = `
291291
Object {
292292
"calldataByteLength": 548,
293-
"gasUsed": 254014,
293+
"gasUsed": 253891,
294294
}
295295
`;
296296

297297
exports[`Uniswap Gas Tests Trade on UniswapV3 with Universal Router. ERC20 --> ERC20 gas: exactIn, one trade, two hops 1`] = `
298298
Object {
299299
"calldataByteLength": 548,
300-
"gasUsed": 177164,
300+
"gasUsed": 177082,
301301
}
302302
`;
303303

304304
exports[`Uniswap Gas Tests Trade on UniswapV3 with Universal Router. ERC20 --> ERC20 gas: exactOut, one trade, one hop 1`] = `
305305
Object {
306306
"calldataByteLength": 516,
307-
"gasUsed": 115071,
307+
"gasUsed": 115030,
308308
}
309309
`;
310310

311311
exports[`Uniswap Gas Tests Trade on UniswapV3 with Universal Router. ERC20 --> ERC20 gas: exactOut, one trade, three hops 1`] = `
312312
Object {
313313
"calldataByteLength": 548,
314-
"gasUsed": 251172,
314+
"gasUsed": 251049,
315315
}
316316
`;
317317

318318
exports[`Uniswap Gas Tests Trade on UniswapV3 with Universal Router. ERC20 --> ERC20 gas: exactOut, one trade, two hops 1`] = `
319319
Object {
320320
"calldataByteLength": 548,
321-
"gasUsed": 174826,
321+
"gasUsed": 174744,
322322
}
323323
`;
324324

325325
exports[`Uniswap Gas Tests Trade on UniswapV3 with Universal Router. ERC20 --> ETH gas: exactIn swap 1`] = `
326326
Object {
327327
"calldataByteLength": 644,
328-
"gasUsed": 121815,
328+
"gasUsed": 121774,
329329
}
330330
`;
331331

332332
exports[`Uniswap Gas Tests Trade on UniswapV3 with Universal Router. ERC20 --> ETH gas: exactOut swap 1`] = `
333333
Object {
334334
"calldataByteLength": 644,
335-
"gasUsed": 131417,
335+
"gasUsed": 131376,
336336
}
337337
`;
338338

339339
exports[`Uniswap Gas Tests Trade on UniswapV3 with Universal Router. ETH --> ERC20 gas: exactIn swap 1`] = `
340340
Object {
341341
"calldataByteLength": 644,
342-
"gasUsed": 215384,
342+
"gasUsed": 215343,
343343
}
344344
`;
345345

346346
exports[`Uniswap Gas Tests Trade on UniswapV3 with Universal Router. ETH --> ERC20 gas: exactOut swap 1`] = `
347347
Object {
348348
"calldataByteLength": 772,
349-
"gasUsed": 126560,
349+
"gasUsed": 126519,
350350
}
351351
`;
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`UniversalRouter Gas Tests gas: bytecode size 1`] = `14355`;
3+
exports[`UniversalRouter Gas Tests gas: bytecode size 1`] = `14018`;

test/integration-tests/gas-tests/__snapshots__/UniversalVSSwapRouter.gas.test.ts.snap

+10-10
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,32 @@ Object {
77
}
88
`;
99

10-
exports[`Uniswap UX Tests gas: Comparisons Casual Swapper - 3 swaps Permit2 Max Approval Swap 1`] = `1104509`;
10+
exports[`Uniswap UX Tests gas: Comparisons Casual Swapper - 3 swaps Permit2 Max Approval Swap 1`] = `1104105`;
1111

12-
exports[`Uniswap UX Tests gas: Comparisons Casual Swapper - 3 swaps Permit2 Sign Per Swap 1`] = `1138923`;
12+
exports[`Uniswap UX Tests gas: Comparisons Casual Swapper - 3 swaps Permit2 Sign Per Swap 1`] = `1138531`;
1313

1414
exports[`Uniswap UX Tests gas: Comparisons Casual Swapper - 3 swaps SwapRouter02 1`] = `1124979`;
1515

16-
exports[`Uniswap UX Tests gas: Comparisons Frequent Swapper - 10 swaps Permit2 Max Approval Swap 1`] = `3082245`;
16+
exports[`Uniswap UX Tests gas: Comparisons Frequent Swapper - 10 swaps Permit2 Max Approval Swap 1`] = `3081021`;
1717

18-
exports[`Uniswap UX Tests gas: Comparisons Frequent Swapper - 10 swaps Permit2 Sign Per Swap 1`] = `3235804`;
18+
exports[`Uniswap UX Tests gas: Comparisons Frequent Swapper - 10 swaps Permit2 Sign Per Swap 1`] = `3234634`;
1919

2020
exports[`Uniswap UX Tests gas: Comparisons Frequent Swapper - 10 swaps SwapRouter02 1`] = `3195011`;
2121

22-
exports[`Uniswap UX Tests gas: Comparisons Frequent Swapper across 3 swap router versions - 15 swaps across 3 versions Permit2 Max Approval Swap 1`] = `4104504`;
22+
exports[`Uniswap UX Tests gas: Comparisons Frequent Swapper across 3 swap router versions - 15 swaps across 3 versions Permit2 Max Approval Swap 1`] = `4102882`;
2323

24-
exports[`Uniswap UX Tests gas: Comparisons Frequent Swapper across 3 swap router versions - 15 swaps across 3 versions Permit2 Sign Per Swap 1`] = `4308542`;
24+
exports[`Uniswap UX Tests gas: Comparisons Frequent Swapper across 3 swap router versions - 15 swaps across 3 versions Permit2 Sign Per Swap 1`] = `4306992`;
2525

2626
exports[`Uniswap UX Tests gas: Comparisons Frequent Swapper across 3 swap router versions - 15 swaps across 3 versions SwapRouter02 1`] = `4282374`;
2727

28-
exports[`Uniswap UX Tests gas: Comparisons One Time Swapper - Complex Swap Permit2 Max Approval Swap 1`] = `508881`;
28+
exports[`Uniswap UX Tests gas: Comparisons One Time Swapper - Complex Swap Permit2 Max Approval Swap 1`] = `508723`;
2929

30-
exports[`Uniswap UX Tests gas: Comparisons One Time Swapper - Complex Swap Permit2 Sign Per Swap 1`] = `509199`;
30+
exports[`Uniswap UX Tests gas: Comparisons One Time Swapper - Complex Swap Permit2 Sign Per Swap 1`] = `509041`;
3131

3232
exports[`Uniswap UX Tests gas: Comparisons One Time Swapper - Complex Swap SwapRouter02 1`] = `500008`;
3333

34-
exports[`Uniswap UX Tests gas: Comparisons One Time Swapper - Simple Swap Permit2 Max Approval Swap 1`] = `299727`;
34+
exports[`Uniswap UX Tests gas: Comparisons One Time Swapper - Simple Swap Permit2 Max Approval Swap 1`] = `299651`;
3535

36-
exports[`Uniswap UX Tests gas: Comparisons One Time Swapper - Simple Swap Permit2 Sign Per Swap 1`] = `299663`;
36+
exports[`Uniswap UX Tests gas: Comparisons One Time Swapper - Simple Swap Permit2 Sign Per Swap 1`] = `299587`;
3737

3838
exports[`Uniswap UX Tests gas: Comparisons One Time Swapper - Simple Swap SwapRouter02 1`] = `270033`;

0 commit comments

Comments
 (0)