Skip to content

Instantly share code, notes, and snippets.

View bjoveski's full-sized avatar
🐾

Bojan Joveski bjoveski

🐾
View GitHub Profile
contract ForwarderFactory {
function cloneForwarder(address forwarder, uint256 salt)
public returns (Forwarder clonedForwarder) {
address clonedAddress = createClone(forwarder, salt);
Forwarder parentForwarder = Forwarder(forwarder);
clonedForwarder = Forwarder(clonedAddress);
clonedForwarder.init(parentForwarder.destination());
}
function createClone(address target, uint256 salt) private returns (address result) {
function buildCreate2Address(senderAddress, saltHex, bytecode) {
return web3.utils.toChecksumAddress(`0x${web3.utils.sha3(`0x${[
'ff',
senderAddress,
saltHex,
web3.utils.sha3(bytecode)
].map(x => x.replace(/0x/, ''))
.join('')}`).slice(-40)}`);
}
import "./Forwarder.sol";
contract ForwarderFactory {
function initForwarder(address destination, uint256 salt) public returns (Forwarder forwarder) {
bytes memory deploymentData = abi.encodePacked(
type(Forwarder).creationCode,
uint256(destination)
);
assembly {
import "./Forwarder.sol";
contract ForwarderFactory {
function initForwarder(address destination) public returns (Forwarder forwarder) {
forwarder = Forwarder.new(destination);
}
}
contract Forwarder {
address public destination;
constructor(address _destination) public {
destination = _destination;
}
function flushERC20(address tokenContractAddress) public {
IERC20 tokenContract = ERC20(tokenContractAddress);
uint256 forwarderBalance = tokenContract.balanceOf(address(this));

Keybase proof

I hereby claim:

  • I am bjoveski on github.
  • I am bojan (https://keybase.io/bojan) on keybase.
  • I have a public key whose fingerprint is 64DF DE8A EA00 6E84 3CFE D463 F06E ADBF AAE2 BD23

To claim this, I am signing this object:

Keybase proof

I hereby claim:

  • I am bjoveski on github.
  • I am bojan (https://keybase.io/bojan) on keybase.
  • I have a public key whose fingerprint is 6E35 8251 8933 CEA9 C9D6 D690 5B2A 86D6 3886 90C0

To claim this, I am signing this object: