文件 1 的 5:Admin.sol
pragma solidity ^0.7.6;
contract Admin {
event NewAdmin(address oldAdmin, address newAdmin);
address payable internal admin;
modifier adminOnly() {
require(msg.sender == admin, '1');
_;
}
function setNewAdmin(address payable _newAdmin) external adminOnly {
address _oldAdmin = admin;
admin = _newAdmin;
emit NewAdmin(_oldAdmin, _newAdmin);
}
}
文件 2 的 5:Errors.sol
pragma solidity ^0.7.6;
library Errors {
string public constant CALLER_NOT_ADMIN = '1';
string public constant CALLER_NOT_CONTROLLER = '29';
string public constant CALLER_NOT_ALLOWED_POOL = '30';
string public constant CALLER_NOT_MINTER = '31';
string public constant FAIL_TRANSFER = '2';
string public constant FAIL_TRANSFER_FROM = '3';
string public constant BALANCE_TOO_LOW = '4';
string public constant ALLOWANCE_TOO_LOW = '5';
string public constant SELF_TRANSFER = '6';
string public constant INSUFFICIENT_CASH = '9';
string public constant INSUFFICIENT_BALANCE = '10';
string public constant FAIL_DEPOSIT = '11';
string public constant FAIL_LOAN_INITIATE = '12';
string public constant FAIL_BORROW = '13';
string public constant ZERO_BORROW = '27';
string public constant BORROW_INSUFFICIENT_FEES = '23';
string public constant LOAN_CLOSED = '14';
string public constant NOT_LOAN_OWNER = '15';
string public constant LOAN_OWNER = '16';
string public constant FAIL_LOAN_EXPAND = '17';
string public constant NOT_KILLABLE = '18';
string public constant RESERVE_FUNDS_INSUFFICIENT = '19';
string public constant FAIL_MINT = '20';
string public constant FAIL_BURN = '21';
string public constant FAIL_WITHDRAW = '24';
string public constant FAIL_CLOSE_BORROW = '25';
string public constant FAIL_KILL_BORROW = '26';
string public constant ZERO_ADDRESS = '22';
string public constant INVALID_PARAMETERS = '28';
string public constant FAIL_LOAN_DELEGATEE_CHANGE = '32';
string public constant FAIL_LOAN_TOKEN_BURN = '33';
string public constant FEES_ACCRUED_INSUFFICIENT = '34';
}
文件 3 的 5:IERC20.sol
pragma solidity ^0.7.6;
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
文件 4 的 5:PalToken.sol
pragma solidity ^0.7.6;
import "./utils/SafeMath.sol";
import "./utils/IERC20.sol";
import "./utils/Admin.sol";
import {Errors} from "./utils/Errors.sol";
contract PalToken is IERC20, Admin {
using SafeMath for uint;
string public name;
string public symbol;
uint public decimals;
uint private _totalSupply;
bool private initialized;
address public palPool;
mapping(address => uint) internal balances;
mapping(address => mapping (address => uint)) internal transferAllowances;
modifier onlyPool() {
require(msg.sender == palPool);
_;
}
constructor (string memory name_, string memory symbol_) {
admin = msg.sender;
name = name_;
symbol = symbol_;
decimals = 18;
initialized = false;
}
function initiate(address _palPool) external adminOnly returns (bool){
require(!initialized);
initialized = true;
palPool = _palPool;
return true;
}
function totalSupply() external override view returns (uint256){
return _totalSupply;
}
function transfer(address dest, uint amount) external override returns(bool){
return _transfer(msg.sender, dest, amount);
}
function transferFrom(address src, address dest, uint amount) external override returns(bool){
require(transferAllowances[src][msg.sender] >= amount, Errors.ALLOWANCE_TOO_LOW);
transferAllowances[src][msg.sender] = transferAllowances[src][msg.sender].sub(amount);
_transfer(src, dest, amount);
return true;
}
function _transfer(address src, address dest, uint amount) internal returns(bool){
require(balances[src] >= amount, Errors.BALANCE_TOO_LOW);
require(dest != src, Errors.SELF_TRANSFER);
require(src != address(0) && dest != address(0), Errors.ZERO_ADDRESS);
balances[src] = balances[src].sub(amount);
balances[dest] = balances[dest].add(amount);
emit Transfer(src,dest,amount);
return true;
}
function approve(address spender, uint amount) external override returns(bool){
return _approve(msg.sender, spender, amount);
}
function increaseAllowance(address spender, uint256 addedValue) external returns (bool) {
return _approve(msg.sender, spender, transferAllowances[msg.sender][spender].add(addedValue));
}
function decreaseAllowance(address spender, uint256 subtractedValue) external returns (bool) {
uint256 currentAllowance = transferAllowances[msg.sender][spender];
require(currentAllowance >= subtractedValue, "decreased allowance below zero");
return _approve(msg.sender, spender, currentAllowance.sub(subtractedValue));
}
function _approve(address owner, address spender, uint amount) internal returns(bool){
require(spender != address(0), Errors.ZERO_ADDRESS);
transferAllowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
return true;
}
function allowance(address owner, address spender) external view override returns(uint){
return transferAllowances[owner][spender];
}
function balanceOf(address owner) external view override returns(uint){
return balances[owner];
}
function mint(address _user, uint _toMint) external onlyPool returns(bool){
require(_user != address(0), Errors.ZERO_ADDRESS);
_totalSupply = _totalSupply.add(_toMint);
balances[_user] = balances[_user].add(_toMint);
emit Transfer(address(0),_user,_toMint);
return true;
}
function burn(address _user, uint _toBurn) external onlyPool returns(bool){
require(_user != address(0), Errors.ZERO_ADDRESS);
require(balances[_user] >= _toBurn, Errors.INSUFFICIENT_BALANCE);
_totalSupply = _totalSupply.sub(_toBurn);
balances[_user] = balances[_user].sub(_toBurn);
emit Transfer(_user,address(0),_toBurn);
return true;
}
}
文件 5 的 5:SafeMath.sol
pragma solidity ^0.7.6;
library SafeMath {
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
function add(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, errorMessage);
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction underflow");
}
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
function mul(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, errorMessage);
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
return c;
}
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
}
{
"compilationTarget": {
"contracts/PalToken.sol": "PalToken"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 25000
},
"remappings": []
}
[{"inputs":[{"internalType":"string","name":"name_","type":"string"},{"internalType":"string","name":"symbol_","type":"string"}],"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":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"oldAdmin","type":"address"},{"indexed":false,"internalType":"address","name":"newAdmin","type":"address"}],"name":"NewAdmin","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"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"},{"internalType":"uint256","name":"_toBurn","type":"uint256"}],"name":"burn","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_palPool","type":"address"}],"name":"initiate","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"},{"internalType":"uint256","name":"_toMint","type":"uint256"}],"name":"mint","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"palPool","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address payable","name":"_newAdmin","type":"address"}],"name":"setNewAdmin","outputs":[],"stateMutability":"nonpayable","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":[{"internalType":"address","name":"dest","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"src","type":"address"},{"internalType":"address","name":"dest","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]