文件 1 的 4:CrowdfundProxy.sol
pragma solidity 0.8.6;
import {CrowdfundStorage} from "./CrowdfundStorage.sol";
import {ERC20Storage} from "../../../external/ERC20Storage.sol";
import {IERC20Events} from "../../../external/interface/IERC20.sol";
interface ICrowdfundFactory {
function mediaAddress() external returns (address);
function logic() external returns (address);
function parameters()
external
returns (
address payable fundingRecipient,
uint256 fundingCap,
uint256 operatorPercent,
uint256 feePercentage
);
}
contract CrowdfundProxy is CrowdfundStorage, ERC20Storage, IERC20Events {
event Upgraded(address indexed implementation);
bytes32 internal constant _IMPLEMENTATION_SLOT =
0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
constructor(
address treasuryConfig_,
address payable operator_,
string memory name_,
string memory symbol_
) ERC20Storage(name_, symbol_) {
address logic = ICrowdfundFactory(msg.sender).logic();
assembly {
sstore(_IMPLEMENTATION_SLOT, logic)
}
emit Upgraded(logic);
(
fundingRecipient,
fundingCap,
operatorPercent,
feePercentage
) = ICrowdfundFactory(msg.sender).parameters();
operator = operator_;
treasuryConfig = treasuryConfig_;
status = Status.FUNDING;
}
function logic() external view returns (address logic_) {
assembly {
logic_ := sload(_IMPLEMENTATION_SLOT)
}
}
fallback() external payable {
assembly {
let ptr := mload(0x40)
calldatacopy(ptr, 0, calldatasize())
let result := delegatecall(
gas(),
sload(_IMPLEMENTATION_SLOT),
ptr,
calldatasize(),
0,
0
)
let size := returndatasize()
returndatacopy(ptr, 0, size)
switch result
case 0 {
revert(ptr, size)
}
default {
return(ptr, size)
}
}
}
receive() external payable {}
}
文件 2 的 4:CrowdfundStorage.sol
pragma solidity 0.8.6;
contract CrowdfundStorage {
enum Status {
FUNDING,
TRADING
}
uint16 internal constant TOKEN_SCALE = 1000;
uint256 internal constant REENTRANCY_NOT_ENTERED = 1;
uint256 internal constant REENTRANCY_ENTERED = 2;
uint256 internal reentrancy_status;
address payable public operator;
address payable public fundingRecipient;
address public treasuryConfig;
uint256 public fundingCap;
uint256 public feePercentage;
uint256 public operatorPercent;
Status public status;
}
文件 3 的 4:ERC20Storage.sol
pragma solidity 0.8.6;
contract ERC20Storage {
string public name;
string public symbol;
uint256 public totalSupply;
constructor(string memory name_, string memory symbol_) {
name = name_;
symbol = symbol_;
totalSupply = 0;
}
}
文件 4 的 4:IERC20.sol
pragma solidity 0.8.6;
interface IERC20 {
function name() external returns (string calldata);
function symbol() external returns (string calldata);
function decimals() external returns (uint8);
function totalSupply() external returns (uint256);
function balanceOf(address account) external returns (uint256);
function allowance(address owner, address spender)
external
returns (uint256);
function approve(address spender, uint256 value) external returns (bool);
function transfer(address to, uint256 value) external returns (bool);
function transferFrom(
address from,
address to,
uint256 value
) external returns (bool);
}
interface IERC20Events {
event Mint(address indexed to, uint256 amount);
event Approval(
address indexed from,
address indexed spender,
uint256 value
);
event Transfer(address indexed from, address indexed to, uint256 value);
}
{
"compilationTarget": {
"contracts/producers/crowdfunds/crowdfund/CrowdfundProxy.sol": "CrowdfundProxy"
},
"evmVersion": "berlin",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 2000
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"treasuryConfig_","type":"address"},{"internalType":"address payable","name":"operator_","type":"address"},{"internalType":"string","name":"name_","type":"string"},{"internalType":"string","name":"symbol_","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Mint","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"Upgraded","type":"event"},{"stateMutability":"payable","type":"fallback"},{"inputs":[],"name":"feePercentage","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"fundingCap","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"fundingRecipient","outputs":[{"internalType":"address payable","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"logic","outputs":[{"internalType":"address","name":"logic_","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"operator","outputs":[{"internalType":"address payable","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"operatorPercent","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"status","outputs":[{"internalType":"enum CrowdfundStorage.Status","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"treasuryConfig","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]