PWN Deployer

1. Summary

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.

3. Contract details

  • PWNDeployer.sol is written in Solidity version 0.8.16

Features

  • 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

Inherited contracts, implemented Interfaces and ERCs

Functions

deploy

Overview

This function deploys a new contract with given salt.

This function takes two arguments supplied by the owner:

  • bytes32salt - Salt to use in the CREATE2 call

  • bytes memorybytecode - Encoded code for contract creation with included constructor arguments

Implementation

function deploy(bytes32 salt, bytes memory bytecode) external onlyOwner returns (address) {
    return Create2.deploy(0, salt, bytecode);
}
deployAndTransferOwnership

Overview

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:

  • bytes32salt - Salt to use in the CREATE2 call

  • addressowner - Address to transfer the ownership to

  • bytes memorybytecode - Encoded code for contract creation with included constructor arguments

Implementation

function deployAndTransferOwnership(bytes32 salt, address owner, bytes memory bytecode) external onlyOwner returns (address deployedContract) {
    deployedContract = Create2.deploy(0, salt, bytecode);
    Ownable(deployedContract).transferOwnership(owner);
}

View Functions

computeAddress

Overview

Computes the address of a contract that would be deployed with a given salt.

This function takes two arguments supplied by the caller:

  • bytes32salt - Salt that would be used in the CREATE2 call

  • bytes32bytecodeHash - Hash of the encoded code for contract creation with included constructor arguments

Implementation

function computeAddress(bytes32 salt, bytes32 bytecodeHash) external view returns (address) {
    return Create2.computeAddress(salt, bytecodeHash);
}

Last updated