@uniswap/v3-periphery-optimism
v1.1.0-rc.1
Published
๐ Optimism fork of peripheral smart contracts for interacting with Uniswap V3 on Optimism
Downloads
32
Readme
Uniswap V3 Periphery Optimism
This repository contains the Optimism fork of the periphery smart contracts for the Uniswap V3 Protocol. For the lower level core contracts, see the uniswap-v3-core-optimism repository.
Testing
Because these contracts and tests are modified for OVM support, there are some changes that mean we can no longer simply run yarn test
and yarn test:ovm
and expect all tests to pass for both the EVM and OVM. There are a few reasons for this:
- EVM vs. OVM contracts will use different amounts of gas, so the gas tests will fail
PoolAddress.sol
has a hardcoded bytecode hash, but this hash will be different for EVM vs. OVM bytecode- In Uniswap V3 Core and Periphery contracts some logic was pulled out into library contracts to reduce contract size. The original EVM contracts had deterministic bytecode, so a bytecode hash can be easily hardcoded in
PoolAddress.sol
, but this is no longer true. The contracts now require linking libraries, and therefore the bytecode and bytecode hash is dependent on the library addresses, which are dependent on the deployer account and nonce
Therefore, we must follow the steps below to run EVM tests in this repo:
- Run
UPDATE_SNAPSHOT=1 yarn test
which will ensure gas costs snapshots are updated (i.e. tests will not fail for gas cost reasons)
And to run OVM tests:
- Run
yarn postinstall
to apply a patch that adds OVM mock contract support to Waffle - Run
UPDATE_SNAPSHOT=1 yarn test:ovm
which will ensure gas costs snapshots are updated (i.e. tests will not fail for gas cost reasons) - On subsequent test runs, run
yarn optimism-down && yarn optimism-up && UPDATE_SNAPSHOT=1 yarn test:ovm
. This is required so the deployer account nonce is reset to zero, which is necessary to get the above bytecode hash when deploying contracts
Both test commands (yarn test
and yarn test:ovm
) will automatically update the POOL_INIT_CODE_HASH
in PoolAddress.sol
as needed for testing.
Note that the _Setup.spec.ts
test file must always be run first. This ensures library addresses (which are dependent on account nonce) are always the same, which ensures the bytecode hash is the same on each test run.