mirror of
https://github.com/autistic-symposium/web3-starter-sol.git
synced 2025-07-25 07:55:25 -04:00
Clean up
This commit is contained in:
parent
c2d0866191
commit
db37d209ab
58 changed files with 4663 additions and 1043 deletions
64
advanced_knowledge/proxies/deploy.sol
Normal file
64
advanced_knowledge/proxies/deploy.sol
Normal file
|
@ -0,0 +1,64 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.17;
|
||||
|
||||
contract Proxy {
|
||||
event Deploy(address);
|
||||
|
||||
receive() external payable {}
|
||||
|
||||
function deploy(bytes memory _code) external payable returns (address addr) {
|
||||
assembly {
|
||||
// create(v, p, n)
|
||||
// v = amount of ETH to send
|
||||
// p = pointer in memory to start of code
|
||||
// n = size of code
|
||||
addr := create(callvalue(), add(_code, 0x20), mload(_code))
|
||||
}
|
||||
// return address 0 on error
|
||||
require(addr != address(0), "deploy failed");
|
||||
|
||||
emit Deploy(addr);
|
||||
}
|
||||
|
||||
function execute(address _target, bytes memory _data) external payable {
|
||||
(bool success, ) = _target.call{value: msg.value}(_data);
|
||||
require(success, "failed");
|
||||
}
|
||||
}
|
||||
|
||||
contract TestContract1 {
|
||||
address public owner = msg.sender;
|
||||
|
||||
function setOwner(address _owner) public {
|
||||
require(msg.sender == owner, "not owner");
|
||||
owner = _owner;
|
||||
}
|
||||
}
|
||||
|
||||
contract TestContract2 {
|
||||
address public owner = msg.sender;
|
||||
uint public value = msg.value;
|
||||
uint public x;
|
||||
uint public y;
|
||||
|
||||
constructor(uint _x, uint _y) payable {
|
||||
x = _x;
|
||||
y = _y;
|
||||
}
|
||||
}
|
||||
|
||||
contract Helper {
|
||||
function getBytecode1() external pure returns (bytes memory) {
|
||||
bytes memory bytecode = type(TestContract1).creationCode;
|
||||
return bytecode;
|
||||
}
|
||||
|
||||
function getBytecode2(uint _x, uint _y) external pure returns (bytes memory) {
|
||||
bytes memory bytecode = type(TestContract2).creationCode;
|
||||
return abi.encodePacked(bytecode, abi.encode(_x, _y));
|
||||
}
|
||||
|
||||
function getCalldata(address _owner) external pure returns (bytes memory) {
|
||||
return abi.encodeWithSignature("setOwner(address)", _owner);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue