PWNDeployer.sol contract manages deployments of the PWN Protocol contracts. It uses the Open-Zeppelin Create2 library to deploy contracts with the same addresses on all chains.
{% embed url="https://github.com/PWNFinance/pwn_deployer/blob/main/src/PWNDeployer.sol" %} GitHub {% endembed %}
- PWNDeployer.sol is written in Solidity version 0.8.16
- Deploy new contracts
- For ownable contracts, the deployer can transfer ownership to a supplied address
- Provides a function to compute an address of a contract is deployed
deploy
This function deploys a new contract with given salt.
This function takes two arguments supplied by the owner:
bytes32
salt
- Salt to use in the CREATE2 callbytes memory
bytecode
- Encoded code for contract creation with included constructor arguments
function deploy(bytes32 salt, bytes memory bytecode) external onlyOwner returns (address) {
return Create2.deploy(0, salt, bytecode);
}
deployAndTransferOwnership
This function deploys a new contract with given salt and transfers ownership of the deployed contract to the supplied address. It is expected for the deployed contract to implement Ownable.
This function takes three arguments supplied by the owner:
bytes32
salt
- Salt to use in the CREATE2 calladdress
owner
- Address to transfer the ownership tobytes memory
bytecode
- Encoded code for contract creation with included constructor arguments
function deployAndTransferOwnership(bytes32 salt, address owner, bytes memory bytecode) external onlyOwner returns (address deployedContract) {
deployedContract = Create2.deploy(0, salt, bytecode);
Ownable(deployedContract).transferOwnership(owner);
}
computeAddress
Computes the address of a contract that would be deployed with a given salt.
This function takes two arguments supplied by the caller:
bytes32
salt
- Salt that would be used in the CREATE2 callbytes32
bytecodeHash
- Hash of the encoded code for contract creation with included constructor arguments
function computeAddress(bytes32 salt, bytes32 bytecodeHash) external view returns (address) {
return Create2.computeAddress(salt, bytecodeHash);
}