Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zkSync style to compute deterministic address #2

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ typechain/
cache-zk/
artifacts-zk/
.env
.DS_Store
__snapshots__
26 changes: 17 additions & 9 deletions contracts/libraries/PoolAddress.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ pragma solidity >=0.5.0;

/// @title Provides functions for deriving a pool address from the factory, tokens, and the fee
library PoolAddress {
bytes32 internal constant POOL_INIT_CODE_HASH = 0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54;
bytes32 internal constant POOL_INIT_CODE_HASH = 0x010011b5a863aee85f9ffb9ff5152cfcd202f5f5ce21f1aeb7c57d30537ffb28;
bytes32 constant CREATE2_PREFIX = 0x2020dba91b30cc0006188af794c2fb30dd8520db7e2c088b7fc7c103c00ca494;
// hash for no constructor args
bytes32 constant constructorInputHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;

/// @notice The identifying key of the pool
struct PoolKey {
Expand All @@ -30,15 +33,20 @@ library PoolAddress {
/// @param factory The Uniswap V3 factory contract address
/// @param key The PoolKey
/// @return pool The contract address of the V3 pool
function computeAddress(address factory, PoolKey memory key) internal view returns (address pool) {
function computeAddress(address factory, PoolKey memory key) internal pure returns (address pool) {
require(key.token0 < key.token1);
(bool success, bytes memory addressBytes) = factory.staticcall(
abi.encodeWithSelector(
bytes4(keccak256("getPool(address,address,uint24)")), key.token0, key.token1, key.fee)
pool = address(
uint256(
keccak256(
abi.encodePacked(
CREATE2_PREFIX,
bytes32(uint256(uint160(factory))),
keccak256(abi.encode(key.token0, key.token1, key.fee)),
POOL_INIT_CODE_HASH,
constructorInputHash
)
)
)
);

require(success);
pool = abi.decode(addressBytes, (address));
require(pool != address(0));
}
}
20 changes: 11 additions & 9 deletions contracts/test/NFTDescriptorTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@ contract NFTDescriptorTest {
return NFTDescriptor.constructTokenURI(params);
}

function getGasCostOfConstructTokenURI(NFTDescriptor.ConstructTokenURIParams calldata params)
public
view
returns (uint256)
{
uint256 gasBefore = gasleft();
NFTDescriptor.constructTokenURI(params);
return gasBefore - gasleft();
}
// no issue here, comment out to solve over contract size issue
// can comment back when need to run test with this function
// function getGasCostOfConstructTokenURI(NFTDescriptor.ConstructTokenURIParams calldata params)
// public
// view
// returns (uint256)
// {
// uint256 gasBefore = gasleft();
// NFTDescriptor.constructTokenURI(params);
// return gasBefore - gasleft();
// }

function tickToDecimalString(
int24 tick,
Expand Down
3 changes: 2 additions & 1 deletion contracts/test/TestMulticall.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ contract TestMulticall is Multicall {
uint256 public paid;

function pays() external payable {
paid += msg.value;
// paid += msg.value; // msg.value in zksync evm always return 0
paid += address(this).balance;
}

function returnSender() external view returns (address) {
Expand Down
2 changes: 1 addition & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,4 @@ export default {
verbose: true,
},
},
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"zksync-web3": "^0.14.3"
},
"devDependencies": {
"@matterlabs/hardhat-zksync-toolbox": "^0.1.1",
"@matterlabs/hardhat-zksync-verify": "^0.1.5",
"@nomiclabs/hardhat-ethers": "^2.0.2",
"@nomiclabs/hardhat-etherscan": "^3.1.7",
Expand Down
4 changes: 4 additions & 0 deletions test/contracts/UniswapV3Factory.sol/UniswapV3Factory.dbg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../build-info/3021134a6e52eeba91b0d2a1125ef6e2.json"
}
248 changes: 248 additions & 0 deletions test/contracts/UniswapV3Factory.sol/UniswapV3Factory.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions test/contracts/UniswapV3Pool.sol/UniswapV3Pool.dbg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../build-info/3021134a6e52eeba91b0d2a1125ef6e2.json"
}
Loading