Skip to content

Commit 139adc7

Browse files
add 3 trade gas test
1 parent 19359e1 commit 139adc7

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

test/SwapRouter.gas.spec.ts

+38-2
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ describe('SwapRouter gas tests', function () {
329329
await snapshotGasCost(router.connect(trader).multicall(data))
330330
})
331331

332-
it('2 trades (directly to sender)', async () => {
332+
it('3 trades (directly to sender)', async () => {
333333
await weth9.connect(trader).deposit({ value: 3 })
334334
await weth9.connect(trader).approve(router.address, constants.MaxUint256)
335335
const swap0 = {
@@ -341,7 +341,15 @@ describe('SwapRouter gas tests', function () {
341341
}
342342

343343
const swap1 = {
344-
path: encodePath([tokens[1].address, tokens[0].address], [FeeAmount.MEDIUM]),
344+
path: encodePath([tokens[0].address, tokens[1].address], [FeeAmount.MEDIUM]),
345+
recipient: trader.address,
346+
deadline: 1,
347+
amountIn: 3,
348+
amountOutMinimum: 1,
349+
}
350+
351+
const swap2 = {
352+
path: encodePath([tokens[1].address, tokens[2].address], [FeeAmount.MEDIUM]),
345353
recipient: trader.address,
346354
deadline: 1,
347355
amountIn: 3,
@@ -351,12 +359,40 @@ describe('SwapRouter gas tests', function () {
351359
const data = [
352360
router.interface.encodeFunctionData('exactInput', [swap0]),
353361
router.interface.encodeFunctionData('exactInput', [swap1]),
362+
router.interface.encodeFunctionData('exactInput', [swap2]),
354363
]
355364

356365
await snapshotGasCost(router.connect(trader).multicall(data))
357366
})
358367
})
359368

369+
it('3 trades (directly to sender)', async () => {
370+
await weth9.connect(trader).deposit({ value: 3 })
371+
await weth9.connect(trader).approve(router.address, constants.MaxUint256)
372+
const swap0 = {
373+
path: encodePath([weth9.address, tokens[0].address], [FeeAmount.MEDIUM]),
374+
recipient: trader.address,
375+
deadline: 1,
376+
amountIn: 3,
377+
amountOutMinimum: 1,
378+
}
379+
380+
const swap1 = {
381+
path: encodePath([tokens[1].address, tokens[0].address], [FeeAmount.MEDIUM]),
382+
recipient: trader.address,
383+
deadline: 1,
384+
amountIn: 3,
385+
amountOutMinimum: 1,
386+
}
387+
388+
const data = [
389+
router.interface.encodeFunctionData('exactInput', [swap0]),
390+
router.interface.encodeFunctionData('exactInput', [swap1]),
391+
]
392+
393+
await snapshotGasCost(router.connect(trader).multicall(data))
394+
})
395+
360396
describe('#exactInputSingle', () => {
361397
it('0 -> 1', async () => {
362398
await snapshotGasCost(exactInputSingle(tokens[0].address, tokens[1].address))

test/__snapshots__/SwapRouter.gas.spec.ts.snap

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ exports[`SwapRouter gas tests #exactInput 2 trades (directly to sender) 1`] = `1
1212

1313
exports[`SwapRouter gas tests #exactInput 2 trades (via router) 1`] = `188802`;
1414

15+
exports[`SwapRouter gas tests #exactInput 3 trades (directly to sender) 1`] = `258723`;
16+
1517
exports[`SwapRouter gas tests #exactInput WETH9 -> 0 1`] = `106071`;
1618

1719
exports[`SwapRouter gas tests #exactInputSingle 0 -> 1 1`] = `107180`;

0 commit comments

Comments
 (0)