Foundry does not have the tools for interacting with Ethereum proxy contracts that Hardhat does. However, doing so is still very possible. In this repo, I've collected examples of how to deal with proxies in Foundry.
This uses TransparentProxy
for now, with the ProxyAdmin
contract
that it requires.
The src
and test
directories contain some examples of manipulating
UUPS proxies in tests.
TransparentProxy is deployed by a ProxyAdmin contract. The owner of the implementation contract's functions and the owner of ProxyAdmin are the same.
- Deploy a
ProxyAdmin
instance, with your wallet asadmin
- Deploy the implementation contract and get its address
- Deploy the TransparentProxy, setting the ProxyAdmin as the admin
The below example uses Hardhat on Optimism.
- Deploy the new implementation contract and get its address
- Get the address of the
ProxyAdmin
, as below - Call
upgrade(PROXY_ADDR, IMPL_ADDR)
on theProxyAdmin
, as below
Use cast storage
to get the variable in Proxy's storage slot that
stores the ProxyAdmin
's address:
export OP_URL=$(pass keys/alchemy/optimism/endpoint)
export CONTRACT=0x10948Fd0beBb798d5eeb315c00B747D6436173b7
export PROXY_ADMIN_SLOT=0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103
export PROXY_ADMIN=$(cast storage --rpc-url $OP_URL $CONTRACT $PROXY_ADMIN_SLOT | cut -c 1-2,27-)
echo $PROXY_ADMIN
Using the environment already set above. $PRIVATE_KEY
is the owner of the ProxyAdmin
.
export PRIVATE_KEY="
export IMPL_CONTRACT="
export PROXY_CONTRACT="
cast call --rpc-url $OP_URL --private-key $PRIVATE_KEY $PROXY_ADMIN "upgrade(${PROXY_CONTRACT},${IMPL_CONTRACT})"
The src
directory contains
https://github.com/MatinR1/UpgradeableTest/tree/master