feat: initial commit for wtf-contract v2

This commit is contained in:
Bot
2026-08-30 23:16:04 +08:00
commit f2769993b5
74 changed files with 17341 additions and 0 deletions
+58
View File
@@ -0,0 +1,58 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/// @dev Minimal ERC20 for testing. No external imports so it compiles inside the
/// junction tree without needing node_modules packages.
contract MockERC20 {
string public name;
string public symbol;
uint8 public immutable decimals;
uint256 public totalSupply;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
event Transfer(address indexed from, address indexed to, uint256 amount);
event Approval(address indexed owner, address indexed spender, uint256 amount);
constructor(string memory name_, string memory symbol_, uint8 decimals_) {
name = name_;
symbol = symbol_;
decimals = decimals_;
}
function mint(address to, uint256 amount) external {
totalSupply += amount;
balanceOf[to] += amount;
emit Transfer(address(0), to, amount);
}
function approve(address spender, uint256 amount) external returns (bool) {
allowance[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
function transfer(address to, uint256 amount) external returns (bool) {
_transfer(msg.sender, to, amount);
return true;
}
function transferFrom(address from, address to, uint256 amount) external returns (bool) {
uint256 allowed = allowance[from][msg.sender];
if (allowed != type(uint256).max) {
require(allowed >= amount, "MockERC20: insufficient allowance");
allowance[from][msg.sender] = allowed - amount;
}
_transfer(from, to, amount);
return true;
}
function _transfer(address from, address to, uint256 amount) internal {
require(balanceOf[from] >= amount, "MockERC20: insufficient balance");
balanceOf[from] -= amount;
balanceOf[to] += amount;
emit Transfer(from, to, amount);
}
}
+36
View File
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/// @dev Minimal non-upgradeable delegatecall proxy for testing upgradeable
/// contracts (WTFControllerV2 uses an initializer + _disableInitializers()).
contract TestProxy {
bytes32 private constant _IMPLEMENTATION_SLOT =
bytes32(uint256(keccak256("test.proxy.implementation")) - 1);
constructor(address implementation_) {
bytes32 slot = _IMPLEMENTATION_SLOT;
assembly {
sstore(slot, implementation_)
}
}
fallback() external payable {
bytes32 slot = _IMPLEMENTATION_SLOT;
address impl;
assembly {
impl := sload(slot)
}
assembly {
calldatacopy(0, 0, calldatasize())
let result := delegatecall(gas(), impl, 0, calldatasize(), 0, 0)
returndatacopy(0, 0, returndatasize())
switch result
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
}