Address Contract Verified
Address
0xfAc0403a24229d7e2Edd994D50F5940624CBeac2
Balance
0 ETH
Nonce
1
Code Size
6051 bytes
Creator
0xd48b6DC3...f93C at tx 0xcb05dc39...ab8eb9
Indexed Transactions
0
Contract Bytecode
6051 bytes
0x608060405234801561001057600080fd5b50600436106101825760003560e01c80637a9e5e4b116100d8578063a22b35ce1161008c578063bf7e214f11610066578063bf7e214f14610480578063d505accf146104a4578063dd62ed3e146104f557610182565b8063a22b35ce146103fc578063a457c2d714610428578063a9059cbb1461045457610182565b806381a4a6d8116100bd57806381a4a6d8146103cf57806395d89b41146103d75780639e6a1d7d146103df57610182565b80637a9e5e4b146103835780637ecebe00146103a957610182565b8063313ce5671161013a57806342966c681161011457806342966c681461031457806370a082311461033157806379cc67901461035757610182565b8063313ce5671461029c57806339509351146102ba57806340c10f19146102e657610182565b806318160ddd1161016b57806318160ddd1461024457806323b872dd1461025e57806330adf81f1461029457610182565b806306fdde0314610187578063095ea7b314610204575b600080fd5b61018f610523565b6040805160208082528351818301528351919283929083019185019080838360005b838110156101c95781810151838201526020016101b1565b50505050905090810190601f1680156101f65780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6102306004803603604081101561021a57600080fd5b506001600160a01b0381351690602001356105b9565b604080519115158252519081900360200190f35b61024c6105cf565b60408051918252519081900360200190f35b6102306004803603606081101561027457600080fd5b506001600160a01b038135811691602081013590911690604001356105d5565b61024c61063e565b6102a4610662565b6040805160ff9092168252519081900360200190f35b610230600480360360408110156102d057600080fd5b506001600160a01b038135169060200135610686565b610312600480360360408110156102fc57600080fd5b506001600160a01b0381351690602001356106bc565b005b6103126004803603602081101561032a57600080fd5b5035610842565b61024c6004803603602081101561034757600080fd5b50356001600160a01b031661084f565b6103126004803603604081101561036d57600080fd5b506001600160a01b03813516906020013561086a565b6103126004803603602081101561039957600080fd5b50356001600160a01b0316610878565b61024c600480360360208110156103bf57600080fd5b50356001600160a01b03166109e0565b61024c610a07565b61018f610a0d565b610312600480360360208110156103f557600080fd5b5035610a6e565b6103126004803603604081101561041257600080fd5b506001600160a01b038135169060200135610baf565b6102306004803603604081101561043e57600080fd5b506001600160a01b038135169060200135610bf6565b6102306004803603604081101561046a57600080fd5b506001600160a01b038135169060200135610c45565b610488610c52565b604080516001600160a01b039092168252519081900360200190f35b610312600480360360e08110156104ba57600080fd5b506001600160a01b03813581169160208101359091169060408101359060608101359060ff6080820135169060a08101359060c00135610c61565b61024c6004803603604081101561050b57600080fd5b506001600160a01b038135811691602001351661107c565b60038054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156105af5780601f10610584576101008083540402835291602001916105af565b820191906000526020600020905b81548152906001019060200180831161059257829003601f168201915b5050505050905090565b60006105c63384846110a7565b50600192915050565b60025490565b60006105e2848484611193565b610634843361062f85604051806060016040528060288152602001611693602891396001600160a01b038a16600090815260016020908152604080832033845290915290205491906112ee565b6110a7565b5060019392505050565b7f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c981565b7f000000000000000000000000000000000000000000000000000000000000000990565b3360008181526001602090815260408083206001600160a01b038716845290915281205490916105c691859061062f9086611348565b600660009054906101000a90046001600160a01b03166001600160a01b031663fbfa77cf6040518163ffffffff1660e01b815260040160206040518083038186803b15801561070a57600080fd5b505afa15801561071e573d6000803e3d6000fd5b505050506040513d602081101561073457600080fd5b505160408051808201909152600c81527f554e415554484f52495a454400000000000000000000000000000000000000006020820152906001600160a01b031633146107fe5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b838110156107c35781810151838201526020016107ab565b50505050905090810190601f1680156107f05780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5060075481906108175760078290556008829055610833565b60075415801590610829575060085482115b1561083357506008545b61083d83826113a9565b505050565b61084c3382611499565b50565b6001600160a01b031660009081526020819052604090205490565b6108748282610baf565b5050565b600660009054906101000a90046001600160a01b03166001600160a01b0316630c340a246040518163ffffffff1660e01b815260040160206040518083038186803b1580156108c657600080fd5b505afa1580156108da573d6000803e3d6000fd5b505050506040513d60208110156108f057600080fd5b505160408051808201909152600c81527f554e415554484f52495a454400000000000000000000000000000000000000006020820152906001600160a01b0316331461097d5760405162461bcd60e51b81526020600482018181528351602484015283519092839260449091019190850190808383600083156107c35781810151838201526020016107ab565b50600680547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b0383169081179091556040517f2f658b440c35314f52658ea8a740e05b284cdc84dc9ae01e891f21b8933e7cad90600090a250565b6001600160a01b0381166000908152600560205260408120610a0190611595565b92915050565b60075490565b60048054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156105af5780601f10610584576101008083540402835291602001916105af565b600660009054906101000a90046001600160a01b03166001600160a01b031663452a93206040518163ffffffff1660e01b815260040160206040518083038186803b158015610abc57600080fd5b505afa158015610ad0573d6000803e3d6000fd5b505050506040513d6020811015610ae657600080fd5b505160408051808201909152600c81527f554e415554484f52495a454400000000000000000000000000000000000000006020820152906001600160a01b03163314610b735760405162461bcd60e51b81526020600482018181528351602484015283519092839260449091019190850190808383600083156107c35781810151838201526020016107ab565b5060088190556040805182815290517f8e6bdaa9228cc80c539ddb4a138adcc9ad64d82fa6153c853411ed120a7bd7059181900360200190a150565b6000610bdf826040518060600160405280602481526020016116bb60249139610bd8863361107c565b91906112ee565b9050610bec8333836110a7565b61083d8383611499565b60006105c6338461062f85604051806060016040528060258152602001611749602591393360009081526001602090815260408083206001600160a01b038d16845290915290205491906112ee565b60006105c6338484611193565b6006546001600160a01b031681565b83421115610cb6576040805162461bcd60e51b815260206004820152601860248201527f5065726d69743a206578706972656420646561646c696e650000000000000000604482015290519081900360640190fd5b6001600160a01b03871660009081526005602052604081204691907f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9908a908a908a90610d0290611595565b8a60405160200180878152602001866001600160a01b03168152602001856001600160a01b03168152602001848152602001838152602001828152602001965050505050505060405160208183030381529060405280519060200120905060006119017f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f610d8e610523565b8051602091820120604080518082018252600181527f310000000000000000000000000000000000000000000000000000000000000090840152805180840194909452838101919091527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc66060840152608083018790523060a0808501919091528151808503909101815260c08401825280519083012060f09490941b7fffff0000000000000000000000000000000000000000000000000000000000001660e084015260e283019390935261010280830186905283518084039091018152610122909201909252805191012090507f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0841115610ef2576040805162461bcd60e51b815260206004820152601b60248201527f696e76616c6964207369676e6174757265202773272076616c75650000000000604482015290519081900360640190fd5b8560ff16601b1480610f0757508560ff16601c145b610f58576040805162461bcd60e51b815260206004820152601b60248201527f696e76616c6964207369676e6174757265202776272076616c75650000000000604482015290519081900360640190fd5b600060018288888860405160008152602001604052604051808581526020018460ff1681526020018381526020018281526020019450505050506020604051602081039080840390855afa158015610fb4573d6000803e3d6000fd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe001519150506001600160a01b0381161580159061100857508a6001600160a01b0316816001600160a01b0316145b6110435760405162461bcd60e51b81526004018080602001828103825260218152602001806116726021913960400191505060405180910390fd5b6001600160a01b038b16600090815260056020526040902061106490611599565b61106f8b8b8b6110a7565b5050505050505050505050565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6001600160a01b0383166110ec5760405162461bcd60e51b81526004018080602001828103825260248152602001806117256024913960400191505060405180910390fd5b6001600160a01b0382166111315760405162461bcd60e51b815260040180806020018281038252602281526020018061162a6022913960400191505060405180910390fd5b6001600160a01b03808416600081815260016020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6001600160a01b0383166111d85760405162461bcd60e51b81526004018080602001828103825260258152602001806117006025913960400191505060405180910390fd5b6001600160a01b03821661121d5760405162461bcd60e51b81526004018080602001828103825260238152602001806115e56023913960400191505060405180910390fd5b61122883838361083d565b6112658160405180606001604052806026815260200161164c602691396001600160a01b03861660009081526020819052604090205491906112ee565b6001600160a01b0380851660009081526020819052604080822093909355908416815220546112949082611348565b6001600160a01b038084166000818152602081815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b600081848411156113405760405162461bcd60e51b81526020600482018181528351602484015283519092839260449091019190850190808383600083156107c35781810151838201526020016107ab565b505050900390565b6000828201838110156113a2576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b9392505050565b6001600160a01b038216611404576040805162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015290519081900360640190fd5b6114106000838361083d565b60025461141d9082611348565b6002556001600160a01b0382166000908152602081905260409020546114439082611348565b6001600160a01b0383166000818152602081815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b6001600160a01b0382166114de5760405162461bcd60e51b81526004018080602001828103825260218152602001806116df6021913960400191505060405180910390fd5b6114ea8260008361083d565b61152781604051806060016040528060228152602001611608602291396001600160a01b03851660009081526020819052604090205491906112ee565b6001600160a01b03831660009081526020819052604090205560025461154d90826115a2565b6002556040805182815290516000916001600160a01b038516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9181900360200190a35050565b5490565b80546001019055565b60006113a283836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f7700008152506112ee56fe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a206275726e20616d6f756e7420657863656564732062616c616e636545524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e63655a65726f537761705065726d69743a20496e76616c6964207369676e617475726545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a206275726e20616d6f756e74206578636565647320616c6c6f77616e636545524332303a206275726e2066726f6d20746865207a65726f206164647265737345524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f206164647265737345524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa2646970667358221220528678ebe8c9439c5aa8a725ffc5b598c633d2a4f2a83c7a331952669291cd2f64736f6c63430007050033
Verified Source Code Full Match
Compiler: v0.7.5+commit.eb77ed08
EVM: istanbul
Optimization: Yes (2000 runs)
ERC20.sol 148 lines
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity >=0.7.5;
import "../Libraries/SafeMath.sol";
import "../Interfaces/IERC20.sol";
abstract contract ERC20 is IERC20 {
using SafeMath for uint256;
// TODO comment actual hash value.
bytes32 private constant ERC20TOKEN_ERC1820_INTERFACE_ID = keccak256("ERC20Token");
mapping(address => uint256) internal _balances;
mapping(address => mapping(address => uint256)) internal _allowances;
uint256 internal _totalSupply;
string internal _name;
string internal _symbol;
uint8 internal immutable _decimals;
constructor(
string memory name_,
string memory symbol_,
uint8 decimals_
) {
_name = name_;
_symbol = symbol_;
_decimals = decimals_;
}
function name() public view returns (string memory) {
return _name;
}
function symbol() public view returns (string memory) {
return _symbol;
}
function decimals() public view virtual returns (uint8) {
return _decimals;
}
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
function transfer(address recipient, uint256 amount) external virtual override returns (bool) {
_transfer(msg.sender, recipient, amount);
return true;
}
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount) external virtual override returns (bool) {
_approve(msg.sender, spender, amount);
return true;
}
function transferFrom(
address sender,
address recipient,
uint256 amount
) external virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(
sender,
msg.sender,
_allowances[sender][msg.sender].sub(amount, "ERC20: transfer amount exceeds allowance")
);
return true;
}
function increaseAllowance(address spender, uint256 addedValue) external virtual returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue));
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) external virtual returns (bool) {
_approve(
msg.sender,
spender,
_allowances[msg.sender][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")
);
return true;
}
function _transfer(
address sender,
address recipient,
uint256 amount
) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
function _approve(
address owner,
address spender,
uint256 amount
) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function _beforeTokenTransfer(
address from_,
address to_,
uint256 amount_
) internal virtual {}
}
IERC20.sol 24 lines
// SPDX-License-Identifier: AGPL-3.0
pragma solidity >=0.7.5;
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);
}
ERC20Permit.sol 66 lines
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity 0.7.5;
import "./ERC20.sol";
import "../Interfaces/IERC2612Permit.sol";
import "../Libraries/Counters.sol";
abstract contract ERC20Permit is ERC20, IERC2612Permit {
using Counters for Counters.Counter;
mapping(address => Counters.Counter) private _nonces;
// keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
bytes32 public constant PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;
/**
* @dev See {IERC2612Permit-permit}.
*
*/
function permit(
address owner,
address spender,
uint256 amount,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external virtual override {
require(block.timestamp <= deadline, "Permit: expired deadline");
uint256 chainID;
assembly {
chainID := chainid()
}
bytes32 hashStruct = keccak256(
abi.encode(PERMIT_TYPEHASH, owner, spender, amount, _nonces[owner].current(), deadline)
);
bytes32 _hash = keccak256(abi.encodePacked(uint16(0x1901),
keccak256(
abi.encode(
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
keccak256(bytes(name())),
keccak256(bytes("1")), // Version
chainID,
address(this)
)
), hashStruct));
require(uint256(s) <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0, "invalid signature 's' value");
require(v == 27 || v == 28, "invalid signature 'v' value");
address signer = ecrecover(_hash, v, r, s);
require(signer != address(0) && signer == owner, "ZeroSwapPermit: Invalid signature");
_nonces[owner].increment();
_approve(owner, spender, amount);
}
/**
* @dev See {IERC2612Permit-nonces}.
*/
function nonces(address owner) external view override returns (uint256) {
return _nonces[owner].current();
}
}
Counters.sol 28 lines
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity 0.7.5;
import "./SafeMath.sol";
library Counters {
using SafeMath for uint256;
struct Counter {
// This variable should never be directly accessed by users of the library: interactions must be restricted to
// the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add
// this feature: see https://github.com/ethereum/solidity/issues/4637
uint256 _value; // default: 0
}
function current(Counter storage counter) internal view returns (uint256) {
return counter._value;
}
function increment(Counter storage counter) internal {
// The {SafeMath} overflow check can be skipped here, see the comment at the top
counter._value += 1;
}
function decrement(Counter storage counter) internal {
counter._value = counter._value.sub(1);
}
}
SafeMath.sol 220 lines
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity 0.7.5;
/**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
// babylonian method (https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method)
function sqrrt(uint256 a) internal pure returns (uint256 c) {
if (a > 3) {
c = a;
uint256 b = add(div(a, 2), 1);
while (b < c) {
c = b;
b = div(add(div(a, b), b), 2);
}
} else if (a != 0) {
c = 1;
}
}
/*
* Expects percentage to be trailed by 00,
*/
function percentageAmount(uint256 total_, uint8 percentage_) internal pure returns (uint256 percentAmount_) {
return div(mul(total_, percentage_), 1000);
}
/*
* Expects percentage to be trailed by 00,
*/
function substractPercentage(uint256 total_, uint8 percentageToSub_) internal pure returns (uint256 result_) {
return sub(total_, div(mul(total_, percentageToSub_), 1000));
}
function percentageOfTotal(uint256 part_, uint256 total_) internal pure returns (uint256 percent_) {
return div(mul(part_, 100), total_);
}
/**
* Taken from Hypersonic https://github.com/M2629/HyperSonic/blob/main/Math.sol
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow, so we distribute
return (a / 2) + (b / 2) + (((a % 2) + (b % 2)) / 2);
}
function quadraticPricing(uint256 payment_, uint256 multiplier_) internal pure returns (uint256) {
return sqrrt(mul(multiplier_, payment_));
}
function bondingCurve(uint256 supply_, uint256 multiplier_) internal pure returns (uint256) {
return mul(multiplier_, supply_);
}
}
TheopetraERC20.sol 68 lines
// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.7.5;
import "../Types/ERC20Permit.sol";
import "../Types/ERC20.sol";
import "../Types/TheopetraAccessControlled.sol";
import "../Libraries/SafeMath.sol";
contract TheopetraERC20Token is ERC20Permit, TheopetraAccessControlled {
using SafeMath for uint256;
event UpdateMintLimit(uint256 mintLimit);
uint256 private _initialSupply;
uint256 private _mintLimit;
constructor(address _authority)
ERC20("Theopetra", "THEO", 9)
TheopetraAccessControlled(ITheopetraAuthority(_authority))
{}
function getInitialSupply() public view returns (uint256) {
return _initialSupply;
}
function setMintLimit(uint256 limit) public onlyGuardian {
_mintLimit = limit;
emit UpdateMintLimit(limit);
}
/** @dev If `_initialSupply` is not zero, the amount to mint is
* limited to at most 5% of `_initialSupply`.
*
* The first time mint is successfully called, it will update the `_initialSupply`
* to equal the mint `amount_`
*
* Note _initialSupply is initialized to zero
*/
function mint(address account_, uint256 amount_) external onlyVault {
uint256 amount = amount_;
if (_initialSupply == 0) {
_initialSupply = amount_;
_mintLimit = _initialSupply;
} else if (_initialSupply != 0 && amount_ > _mintLimit) {
amount = _mintLimit;
}
_mint(account_, amount);
}
function burn(uint256 amount) external virtual {
_burn(msg.sender, amount);
}
function burnFrom(address account_, uint256 amount_) external virtual {
_burnFrom(account_, amount_);
}
function _burnFrom(address account_, uint256 amount_) public virtual {
uint256 decreasedAllowance_ = allowance(account_, msg.sender).sub(
amount_,
"ERC20: burn amount exceeds allowance"
);
_approve(account_, msg.sender, decreasedAllowance_);
_burn(account_, amount_);
}
}
IERC2612Permit.sol 45 lines
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity 0.7.5;
interface IERC2612Permit {
/**
* @dev Sets `amount` as the allowance of `spender` over `owner`'s tokens,
* given `owner`'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*/
function permit(
address owner,
address spender,
uint256 amount,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current ERC2612 nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
}
ITheopetraAuthority.sol 34 lines
// SPDX-License-Identifier: AGPL-3.0
pragma solidity >=0.7.5;
interface ITheopetraAuthority {
/* ========== EVENTS ========== */
event GovernorPushed(address indexed from, address indexed to, bool _effectiveImmediately);
event GuardianPushed(address indexed from, address indexed to, bool _effectiveImmediately);
event PolicyPushed(address indexed from, address indexed to, bool _effectiveImmediately);
event ManagerPushed(address indexed from, address indexed to, bool _effectiveImmediately);
event VaultPushed(address indexed from, address indexed to, bool _effectiveImmediately);
event SignerPushed(address indexed from, address indexed to, bool _effectiveImmediately);
event GovernorPulled(address indexed from, address indexed to);
event GuardianPulled(address indexed from, address indexed to);
event PolicyPulled(address indexed from, address indexed to);
event ManagerPulled(address indexed from, address indexed to);
event VaultPulled(address indexed from, address indexed to);
event SignerPulled(address indexed from, address indexed to);
/* ========== VIEW ========== */
function governor() external view returns (address);
function guardian() external view returns (address);
function policy() external view returns (address);
function manager() external view returns (address);
function vault() external view returns (address);
function whitelistSigner() external view returns (address);
}
TheopetraAccessControlled.sol 57 lines
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.7.5;
import "../Interfaces/ITheopetraAuthority.sol";
abstract contract TheopetraAccessControlled {
/* ========== EVENTS ========== */
event AuthorityUpdated(ITheopetraAuthority indexed authority);
string constant UNAUTHORIZED = "UNAUTHORIZED"; // save gas
/* ========== STATE VARIABLES ========== */
ITheopetraAuthority public authority;
/* ========== Constructor ========== */
constructor(ITheopetraAuthority _authority) {
authority = _authority;
emit AuthorityUpdated(_authority);
}
/* ========== MODIFIERS ========== */
modifier onlyGovernor() {
require(msg.sender == authority.governor(), UNAUTHORIZED);
_;
}
modifier onlyGuardian() {
require(msg.sender == authority.guardian(), UNAUTHORIZED);
_;
}
modifier onlyPolicy() {
require(msg.sender == authority.policy(), UNAUTHORIZED);
_;
}
modifier onlyManager() {
require(msg.sender == authority.manager(), UNAUTHORIZED);
_;
}
modifier onlyVault() {
require(msg.sender == authority.vault(), UNAUTHORIZED);
_;
}
/* ========== GOV ONLY ========== */
function setAuthority(ITheopetraAuthority _newAuthority) external onlyGovernor {
authority = _newAuthority;
emit AuthorityUpdated(_newAuthority);
}
}
Read Contract
PERMIT_TYPEHASH 0x30adf81f → bytes32
allowance 0xdd62ed3e → uint256
authority 0xbf7e214f → address
balanceOf 0x70a08231 → uint256
decimals 0x313ce567 → uint8
getInitialSupply 0x81a4a6d8 → uint256
name 0x06fdde03 → string
nonces 0x7ecebe00 → uint256
symbol 0x95d89b41 → string
totalSupply 0x18160ddd → uint256
Write Contract 12 functions
These functions modify contract state and require a wallet transaction to execute.
_burnFrom 0xa22b35ce
address account_
uint256 amount_
approve 0x095ea7b3
address spender
uint256 amount
returns: bool
burn 0x42966c68
uint256 amount
burnFrom 0x79cc6790
address account_
uint256 amount_
decreaseAllowance 0xa457c2d7
address spender
uint256 subtractedValue
returns: bool
increaseAllowance 0x39509351
address spender
uint256 addedValue
returns: bool
mint 0x40c10f19
address account_
uint256 amount_
permit 0xd505accf
address owner
address spender
uint256 amount
uint256 deadline
uint8 v
bytes32 r
bytes32 s
setAuthority 0x7a9e5e4b
address _newAuthority
setMintLimit 0x9e6a1d7d
uint256 limit
transfer 0xa9059cbb
address recipient
uint256 amount
returns: bool
transferFrom 0x23b872dd
address sender
address recipient
uint256 amount
returns: bool
Token Balances (1)
View Transfers →Recent Transactions
No transactions found for this address