文件 1 的 4:Context.sol
pragma solidity 0.8.9;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
this;
return msg.data;
}
}
文件 2 的 4:IToken.sol
pragma solidity 0.8.9;
pragma experimental ABIEncoderV2;
interface ITokenDelegator {
function _setImplementation(address implementation_) external;
function _setOwner(address owner_) external;
fallback() external payable;
receive() external payable;
}
interface ITokenDelegate {
function initialize(address account_, uint256 initialSupply_) external;
function changeName(string calldata name_) external;
function changeSymbol(string calldata symbol_) external;
function allowance(address account, address spender) external view returns (uint256);
function approve(address spender, uint256 rawAmount) external returns (bool);
function balanceOf(address account) external view returns (uint256);
function transfer(address dst, uint256 rawAmount) external returns (bool);
function transferFrom(
address src,
address dst,
uint256 rawAmount
) external returns (bool);
function mint(address dst, uint256 rawAmount) external;
function permit(
address owner,
address spender,
uint256 rawAmount,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
function delegate(address delegatee) external;
function delegateBySig(
address delegatee,
uint256 nonce,
uint256 expiry,
uint8 v,
bytes32 r,
bytes32 s
) external;
function getCurrentVotes(address account) external view returns (uint96);
function getPriorVotes(address account, uint256 blockNumber) external view returns (uint96);
}
interface TokenEvents {
event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);
event DelegateVotesChanged(address indexed delegate, uint256 previousBalance, uint256 newBalance);
event MinterChanged(address indexed oldMinter, address indexed newMinter);
event Transfer(address indexed from, address indexed to, uint256 amount);
event Approval(address indexed owner, address indexed spender, uint256 amount);
event NewImplementation(address oldImplementation, address newImplementation);
event ChangedSymbol(string oldSybmol, string newSybmol);
event ChangedName(string oldName, string newName);
}
文件 3 的 4:TokenDelegator.sol
pragma solidity 0.8.9;
pragma experimental ABIEncoderV2;
import "./IToken.sol";
import "./TokenStorage.sol";
contract InterestProtocolToken is TokenDelegatorStorage, TokenEvents, ITokenDelegator {
constructor(
address account_,
address owner_,
address implementation_,
uint256 initialSupply_
) {
require(implementation_ != address(0), "TokenDelegator: invalid address");
owner = owner_;
delegateTo(implementation_, abi.encodeWithSignature("initialize(address,uint256)", account_, initialSupply_));
implementation = implementation_;
emit NewImplementation(address(0), implementation);
}
function _setImplementation(address implementation_) external override onlyOwner {
require(implementation_ != address(0), "_setImplementation: invalid addr");
address oldImplementation = implementation;
implementation = implementation_;
emit NewImplementation(oldImplementation, implementation);
}
function _setOwner(address owner_) external override onlyOwner {
owner = owner_;
}
function delegateTo(address callee, bytes memory data) internal {
(bool success, bytes memory returnData) = callee.delegatecall(data);
assembly {
if eq(success, 0) {
revert(add(returnData, 0x20), returndatasize())
}
}
}
fallback() external payable override {
(bool success, ) = implementation.delegatecall(msg.data);
assembly {
let free_mem_ptr := mload(0x40)
returndatacopy(free_mem_ptr, 0, returndatasize())
switch success
case 0 {
revert(free_mem_ptr, returndatasize())
}
default {
return(free_mem_ptr, returndatasize())
}
}
}
receive() external payable override {}
}
文件 4 的 4:TokenStorage.sol
pragma solidity 0.8.9;
pragma experimental ABIEncoderV2;
import "../../_external/Context.sol";
contract TokenDelegatorStorage is Context {
address public implementation;
string public name = "Interest Protocol";
string public symbol = "IPT";
uint256 public totalSupply;
uint8 public constant decimals = 18;
address public owner;
modifier onlyOwner() {
require(owner == _msgSender(), "onlyOwner: sender not owner");
_;
}
}
contract TokenDelegateStorageV1 is TokenDelegatorStorage {
mapping(address => mapping(address => uint96)) internal allowances;
mapping(address => uint96) internal balances;
mapping(address => address) public delegates;
struct Checkpoint {
uint32 fromBlock;
uint96 votes;
}
mapping(address => mapping(uint32 => Checkpoint)) public checkpoints;
mapping(address => uint32) public numCheckpoints;
mapping(address => uint256) public nonces;
}
{
"compilationTarget": {
"contracts/governance/token/TokenDelegator.sol": "InterestProtocolToken"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"account_","type":"address"},{"internalType":"address","name":"owner_","type":"address"},{"internalType":"address","name":"implementation_","type":"address"},{"internalType":"uint256","name":"initialSupply_","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"oldName","type":"string"},{"indexed":false,"internalType":"string","name":"newName","type":"string"}],"name":"ChangedName","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"oldSybmol","type":"string"},{"indexed":false,"internalType":"string","name":"newSybmol","type":"string"}],"name":"ChangedSymbol","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"delegator","type":"address"},{"indexed":true,"internalType":"address","name":"fromDelegate","type":"address"},{"indexed":true,"internalType":"address","name":"toDelegate","type":"address"}],"name":"DelegateChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"delegate","type":"address"},{"indexed":false,"internalType":"uint256","name":"previousBalance","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newBalance","type":"uint256"}],"name":"DelegateVotesChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldMinter","type":"address"},{"indexed":true,"internalType":"address","name":"newMinter","type":"address"}],"name":"MinterChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"oldImplementation","type":"address"},{"indexed":false,"internalType":"address","name":"newImplementation","type":"address"}],"name":"NewImplementation","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":"amount","type":"uint256"}],"name":"Transfer","type":"event"},{"stateMutability":"payable","type":"fallback"},{"inputs":[{"internalType":"address","name":"implementation_","type":"address"}],"name":"_setImplementation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner_","type":"address"}],"name":"_setOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"implementation","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"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"},{"stateMutability":"payable","type":"receive"}]