Skip to content

Commit

Permalink
fix: add gas snaps for swaps with 1155 as input/output (Uniswap#383)
Browse files Browse the repository at this point in the history
* Add snaps for 1155 swaps

* remove lib

* Add gas prefix
  • Loading branch information
zhongeric authored and hyunchel committed Feb 21, 2024
1 parent 6c371bd commit a60595e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions .forge-snapshots/swap mint 1155 as output.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
169555
1 change: 1 addition & 0 deletions .forge-snapshots/swap with 1155 as input.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
155963
8 changes: 6 additions & 2 deletions test/foundry-tests/PoolManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ contract PoolManagerTest is Test, Deployers, TokenFixture, GasSnapshot, IERC1155
snapEnd();
}

function testSwapMintERC1155IfOutputNotTaken() public {
function testGasSwapMintERC1155IfOutputNotTaken() public {
PoolKey memory key =
PoolKey({currency0: currency0, currency1: currency1, fee: 3000, hooks: IHooks(address(0)), tickSpacing: 60});

Expand All @@ -819,13 +819,15 @@ contract PoolManagerTest is Test, Deployers, TokenFixture, GasSnapshot, IERC1155

vm.expectEmit(true, true, true, true);
emit TransferSingle(address(swapRouter), address(0), address(this), CurrencyLibrary.toId(currency1), 98);
snapStart("swap mint 1155 as output");
swapRouter.swap(key, params, testSettings, ZERO_BYTES);
snapEnd();

uint256 erc1155Balance = manager.balanceOf(address(this), CurrencyLibrary.toId(currency1));
assertEq(erc1155Balance, 98);
}

function testSwapUse1155AsInput() public {
function testGasSwapUse1155AsInput() public {
PoolKey memory key =
PoolKey({currency0: currency0, currency1: currency1, fee: 3000, hooks: IHooks(address(0)), tickSpacing: 60});

Expand Down Expand Up @@ -858,7 +860,9 @@ contract PoolManagerTest is Test, Deployers, TokenFixture, GasSnapshot, IERC1155

vm.expectEmit(true, true, true, true);
emit TransferSingle(address(manager), address(manager), address(0), CurrencyLibrary.toId(currency1), 27);
snapStart("swap with 1155 as input");
swapRouter.swap(key, params, testSettings, ZERO_BYTES);
snapEnd();

erc1155Balance = manager.balanceOf(address(this), CurrencyLibrary.toId(currency1));
assertEq(erc1155Balance, 71);
Expand Down

0 comments on commit a60595e

Please sign in to comment.