From a3577d9075bb23a224504b9dd42a72148f315766 Mon Sep 17 00:00:00 2001 From: Shuhui Luo <107524008+shuhuiluo@users.noreply.github.com> Date: Fri, 5 Apr 2024 01:52:45 -0400 Subject: [PATCH 1/3] Update gas snapshots and optimize loop in `EphemeralStorageLens` --- .gas-snapshot | 52 +++++++++++++++--------------- contracts/EphemeralStorageLens.sol | 6 ++-- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/.gas-snapshot b/.gas-snapshot index 2ec3392..f34e310 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -1,26 +1,26 @@ -PCSV3PoolLensTest:testFuzz_GetPositions(int24,int24) (runs: 17, μ: 1274402, ~: 1320751) -PCSV3PoolLensTest:test_GetPopulatedTicksInRange() (gas: 495259) -PCSV3PoolLensTest:test_GetPositions() (gas: 1231579) -PCSV3PoolLensTest:test_GetSlots() (gas: 148865) -PCSV3PoolLensTest:test_GetTickBitmap() (gas: 3140056) -PCSV3PositionLensTest:testFuzz_GetPosition(uint256) (runs: 17, μ: 263786, ~: 262928) -PCSV3PositionLensTest:test_AllPositions() (gas: 17634985) -PCSV3PositionLensTest:test_GetFeesOwed() (gas: 2770490) -PCSV3PositionLensTest:test_GetPositions() (gas: 1075793) -PCSV3PositionLensTest:test_GetTotalAmounts() (gas: 2774508) -PCSV3StorageLensTest:testFuzz_extsload(bytes32) (runs: 257, μ: 33505, ~: 33635) -PCSV3StorageLensTest:test_extsload() (gas: 63395) -PCSV3TickLensTest:test_GetPopulatedTicksInRange() (gas: 726747) -PoolLensTest:testFuzz_GetPositions(int24,int24) (runs: 17, μ: 1272927, ~: 1302846) -PoolLensTest:test_GetPopulatedTicksInRange() (gas: 4194371) -PoolLensTest:test_GetPositions() (gas: 1015456) -PoolLensTest:test_GetSlots() (gas: 3455641) -PoolLensTest:test_GetTickBitmap() (gas: 3155317) -PositionLensTest:testFuzz_GetPosition(uint256) (runs: 17, μ: 260687, ~: 260219) -PositionLensTest:test_AllPositions() (gas: 1027910) -PositionLensTest:test_GetFeesOwed() (gas: 2424302) -PositionLensTest:test_GetPositions() (gas: 839875) -PositionLensTest:test_GetTotalAmounts() (gas: 2436715) -StorageLensTest:testFuzz_extsload(bytes32) (runs: 17, μ: 33500, ~: 33635) -StorageLensTest:test_extsload() (gas: 63395) -TickLensTest:test_GetPopulatedTicksInRange() (gas: 10322483) \ No newline at end of file +PCSV3PoolLensTest:testFuzz_GetPositions(int24,int24) (runs: 17, μ: 1392200, ~: 1437447) +PCSV3PoolLensTest:test_GetPopulatedTicksInRange() (gas: 524480) +PCSV3PoolLensTest:test_GetPositions() (gas: 1348279) +PCSV3PoolLensTest:test_GetSlots() (gas: 151189) +PCSV3PoolLensTest:test_GetTickBitmap() (gas: 3370484) +PCSV3PositionLensTest:testFuzz_GetPosition(uint256) (runs: 17, μ: 274996, ~: 275218) +PCSV3PositionLensTest:test_AllPositions() (gas: 19719373) +PCSV3PositionLensTest:test_GetFeesOwed() (gas: 2791103) +PCSV3PositionLensTest:test_GetPositions() (gas: 1176049) +PCSV3PositionLensTest:test_GetTotalAmounts() (gas: 2794460) +PCSV3StorageLensTest:testFuzz_extsload(bytes32) (runs: 257, μ: 33810, ~: 33944) +PCSV3StorageLensTest:test_extsload() (gas: 66675) +PCSV3TickLensTest:test_GetPopulatedTicksInRange() (gas: 793601) +PoolLensTest:testFuzz_GetPositions(int24,int24) (runs: 17, μ: 1389477, ~: 1419421) +PoolLensTest:test_GetPopulatedTicksInRange() (gas: 4524074) +PoolLensTest:test_GetPositions() (gas: 1132031) +PoolLensTest:test_GetSlots() (gas: 3695636) +PoolLensTest:test_GetTickBitmap() (gas: 3385051) +PositionLensTest:testFuzz_GetPosition(uint256) (runs: 17, μ: 271318, ~: 272509) +PositionLensTest:test_AllPositions() (gas: 1137940) +PositionLensTest:test_GetFeesOwed() (gas: 2444915) +PositionLensTest:test_GetPositions() (gas: 940131) +PositionLensTest:test_GetTotalAmounts() (gas: 2456667) +StorageLensTest:testFuzz_extsload(bytes32) (runs: 17, μ: 33820, ~: 33944) +StorageLensTest:test_extsload() (gas: 66675) +TickLensTest:test_GetPopulatedTicksInRange() (gas: 11472791) \ No newline at end of file diff --git a/contracts/EphemeralStorageLens.sol b/contracts/EphemeralStorageLens.sol index bbd3302..e629d20 100644 --- a/contracts/EphemeralStorageLens.sol +++ b/contracts/EphemeralStorageLens.sol @@ -15,12 +15,12 @@ contract EphemeralStorageLens { let calldataptr := slots.offset // prettier-ignore for { } 1 { } { - if eq(memptr, end) { - break - } mstore(memptr, sload(calldataload(calldataptr))) memptr := add(memptr, 0x20) calldataptr := add(calldataptr, 0x20) + if eq(memptr, end) { + break + } } return(0, end) } From b1edf4d528a7aaebc7a5deee025e05d2fe0ce9d0 Mon Sep 17 00:00:00 2001 From: Shuhui Luo <107524008+shuhuiluo@users.noreply.github.com> Date: Fri, 5 Apr 2024 01:54:04 -0400 Subject: [PATCH 2/3] Update package version to 1.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index abdb56b..66e6c09 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aperture-lens", - "version": "1.0.0", + "version": "1.0.1", "description": "Contains ephemeral lens contracts that can be called without deployment and their interfaces in various Web3 libraries.", "author": "Aperture Finance ", "license": "Apache-2.0", From 5ecb6d932851cc3dd1c05a20698e55c933b391cb Mon Sep 17 00:00:00 2001 From: Shuhui Luo <107524008+shuhuiluo@users.noreply.github.com> Date: Fri, 5 Apr 2024 02:07:26 -0400 Subject: [PATCH 3/3] Update prettier commands and refactor 'if' condition --- contracts/EphemeralStorageLens.sol | 4 +--- package.json | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/contracts/EphemeralStorageLens.sol b/contracts/EphemeralStorageLens.sol index e629d20..f8a0a42 100644 --- a/contracts/EphemeralStorageLens.sol +++ b/contracts/EphemeralStorageLens.sol @@ -18,9 +18,7 @@ contract EphemeralStorageLens { mstore(memptr, sload(calldataload(calldataptr))) memptr := add(memptr, 0x20) calldataptr := add(calldataptr, 0x20) - if eq(memptr, end) { - break - } + if iszero(lt(memptr, end)) { break } } return(0, end) } diff --git a/package.json b/package.json index 66e6c09..d49f8d7 100644 --- a/package.json +++ b/package.json @@ -42,8 +42,8 @@ "test:hardhat": "hardhat test", "snapshot": "forge snapshot --isolate", "snapshot:diff": "forge snapshot --diff --isolate", - "prettier": "prettier -c {contracts,test}/**/*.sol ./**/*.ts", - "prettier:fix": "prettier -w {contracts,test}/**/*.sol ./**/*.ts", + "prettier": "prettier -c contracts/{*,**/*}.sol test/**/*.sol ./**/*.ts", + "prettier:fix": "prettier -w contracts/{*,**/*}.sol test/**/*.sol ./**/*.ts", "typechain": "hardhat typechain" }, "dependencies": {