Skip to content

Instantly share code, notes, and snippets.

@pcaversaccio
Last active June 12, 2022 17:28
Show Gist options
  • Save pcaversaccio/92498ebc709e77460c640db192750298 to your computer and use it in GitHub Desktop.
Save pcaversaccio/92498ebc709e77460c640db192750298 to your computer and use it in GitHub Desktop.
An ERC20 mock contract that is deployed directly with Solidity using the `Create2Deployer`.
// SPDX-License-Identifier: MIT
pragma solidity 0.8.10;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
// Mock class using ERC20
contract ERC20Mock is ERC20 {
constructor(
string memory name,
string memory symbol,
address initialAccount,
uint256 initialBalance
) payable ERC20(name, symbol) {
_mint(initialAccount, initialBalance);
}
function mint(address account, uint256 amount) public {
_mint(account, amount);
}
function burn(address account, uint256 amount) public {
_burn(account, amount);
}
function transferInternal(
address from,
address to,
uint256 value
) public {
_transfer(from, to, value);
}
function approveInternal(
address owner,
address spender,
uint256 value
) public {
_approve(owner, spender, value);
}
}
// ________ .__
// ___ ___\______ \ ____ ______ | | ____ ___.__. ___________
// \ \/ / | | \_/ __ \\____ \| | / _ < | |/ __ \_ __ \
// > < | ` \ ___/| |_> > |_( <_> )___ \ ___/| | \/
// /__/\_ \/_______ /\___ > __/|____/\____// ____|\___ >__|
// \/ \/ \/|__| \/ \/
interface IxDeployer {
function deploy(uint256 value, bytes32 salt, bytes memory code) external;
function computeAddress(bytes32 salt, bytes32 codehash) external returns(address);
}
contract DeployToxDeployer {
string name = "Test";
string symbol = "TST";
address initialAccount = 0x9F3f11d72d96910df008Cfe3aBA40F361D2EED03;
uint256 initialBalance = 0;
IxDeployer x = IxDeployer(0x13b0D85CcB8bf860b6b79AF3029fCA081AE9beF2);
bytes code = abi.encodePacked(type(ERC20Mock).creationCode, abi.encode(name, symbol, initialAccount, initialBalance));
bytes32 salt = keccak256(abi.encode("WAGMI"));
constructor() {
x.deploy(0, salt, code);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment